﻿

using Microsoft.Office.Interop.Excel;
using Microsoft.Win32;
using MiniExcelLibs;
using Newtonsoft.Json;
using Oracle.ManagedDataAccess.Client;
using PanhuaWin;
using PanhuaWin.WMS2NC888;
using PanhuaWin.系统管理;
using StackExchange.Redis;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Web.UI.MobileControls;
using System.Windows.Controls.Primitives;
using System.Windows.Forms;
using System.Xml;
using static PanhuaWin.MAC;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using DataTable = System.Data.DataTable;

namespace PanhuaWin
{
    static class pub
    {

        [DllImport("User32.dll", CharSet = CharSet.Auto)]
        public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);
        public static string Sys_User_Login_Url = ConfigHelper.GetAppConfig("Sys_User_Login_Url");
        public static string Sys_User_modifyPwd_Url = ConfigHelper.GetAppConfig("Sys_User_modifyPwd_Url");
        public static string purchaseConn = "Data Source=113.219.212.5,10010;Initial Catalog=DASContract;Persist Security Info=True;User ID=nc;Password=nc123456;Connect Timeout=500;";
        public static string 全局仓库;
        public static string 全局包装;
        public static string 全局工厂名称= "张家港万达薄板有限公司";
        public static string 全局工厂编号= "1001";
        public static string 全局工厂guid = "9C1D1BD4-9BDF-4C96-AA10-7723BB52C624";
        public static string 全局产线名称;
        public static string 全局产线编号;
        public static string 全局部门名称;
        public static string 全局部门编号;
        public static string 全局部门guid;
        /// <summary>
        /// 返回数据表
        /// </summary>
        /// <param name="ConnectionString">连接字符串</param>
        /// <param name="mysql">查询语句</param>
        /// <returns></returns>

        public static string ConnectionString = ConfigHelper.GetAppConfig("ConnectionString");

        internal static void ListInventory(string 条件, string T_GOOD_TYPE_CODE, UIDataGridView uiDataGridViewInventory)
        {
            string sql;
            sql = @"select [guid]         ,[T_GOOD_NAME]        ,[T_GOOD_CODE]            ,[T_GOOD_TYPE]        ,[T_GOOD_TYPE_CODE]            ,[T_GOOD_MODEL]
      ,[T_GOOD_UNIT]         ,[T_GOOD_PRICE_CUR]        ,[T_EXC_RATE]          ,[T_PRICE_BASE]            ,[T_GOOD_TAX_RATE]
      ,[T_QUALITY]           ,[T_QUALITY_UNIT]         ,[T_GOOD_PRICE_UNIT]           ,[T_GOOD_PRICE_UNIT_CODE]           ,[EXP1]                  ,[T_IS_GOOD]
      ,[T_GOOD_STATUE]          ,[T_GOOD_STATUE_CODE]       ,[T_QUALITY_STAND]             ,[T_GOOD_REMARK]         ,[T_CREATE_DATE]         ,[T_UPDATE_DATE]
      ,[EXP4] 
            FROM [T_VIEW_CIM] where 1=1 ";
            if (T_GOOD_TYPE_CODE != "")
            {
                sql += " and T_GOOD_TYPE_CODE ='" + T_GOOD_TYPE_CODE + "'";
            }
            if (条件 != "")
            {
                sql += " and (T_GOOD_NAME like '%" + 条件 + "%' or T_GOOD_CODE like '%" + 条件 + "%' or T_GOOD_MODEL  like '%" + 条件 + "%' or [EXP4]  like '%" + 条件 + "%' )";
            }
            sql += " order by T_GOOD_TYPE_CODE,T_GOOD_CODE,T_GOOD_NAME,T_GOOD_MODEL ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            uiDataGridViewInventory.AutoGenerateColumns = false;
            uiDataGridViewInventory.DataSource = tb;
            uiDataGridViewInventory.Refresh();

        }

        internal static void ListSupplier(UIComboBox uiComboBox供应商, string 条件)
        {
            string sql;
            sql = @"SELECT   guid, T_RM_ARE, T_RM_ARE_CODE, T_RM_PROVINCE, T_RM_PROVINCE_CODE, T_RM_CITY, T_RM_CITY_CODE, 
                T_RM_NAME, T_RM_CODE,T_RM_CODE+ ' ' +T_RM_NAME CODE_NAME, T_RM_TYPE, T_RM_FL, T_RM_FL_CODE, T_RM_COMPANY_NATURE_CODE, 
                T_RM_COMPANY_NATURE, T_RM_BUSINESS_START_DATE, T_RM_BUSINESS_START_END, T_RM_WORK_STATUE, 
                T_RM_WORK_STATUE_CODE, T_RM_COR_REP, T_RM_REGISTERED_CAPITAL, T_RM_TAXPAYER_QUALIFICATION, 
                T_RM_TAXPAYER_QUALIFICATION_CODE, T_RM_OFFICE_ADD, T_RM_BUSINESS, T_RM_REGISTERED_ADD, 
                T_RM_UNI_CODE, T_RM_BANK_DEPOSIT, T_RM_BANK_DEPOSIT_CODE, T_RM_BANK_NAME, 
                T_RM_BANK_ACCOUNT, T_RM_WEBSITE, T_RM_OFFICE_TEL, T_RM_ZIP_CODE, T_RM_FAX, T_RM_REMARK, EXP2, 
                EXP3, T_CREATE_DATE, T_UPDATE_DATE
FROM      T_VIEW_RM where 1=1 ";
            if (条件 != "")
            {
                sql += " and T_RM_NAME like '%" + 条件 + "%'";
            }
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);

            uiComboBox供应商.DisplayMember = "CODE_NAME";
            uiComboBox供应商.ValueMember = "T_RM_CODE";
            uiComboBox供应商.DataSource = tb;
            uiComboBox供应商.Refresh();
        }

        internal static T_VIEW_CIM getT_VIEW_CIMByT_GOOD_CODE(string 存货编号)
        {
            string sql;
            sql = @"SELECT   guid, T_GOOD_NAME, T_GOOD_CODE, T_GOOD_TYPE, T_GOOD_TYPE_CODE, T_GOOD_MODEL, T_GOOD_UNIT, 
                T_GOOD_PRICE_CUR, T_EXC_RATE, T_PRICE_BASE, T_GOOD_TAX_RATE, T_QUALITY, T_QUALITY_UNIT, 
                T_GOOD_PRICE_UNIT, T_GOOD_PRICE_UNIT_CODE, EXP1, T_IS_GOOD, T_GOOD_STATUE, T_GOOD_STATUE_CODE, 
                T_QUALITY_STAND, T_GOOD_REMARK, T_CREATE_DATE, T_UPDATE_DATE
FROM      T_VIEW_CIM  where T_GOOD_CODE='" + 存货编号 + "'";

            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null)
            {
                List<T_VIEW_CIM> t_view_cims = pub.GetTableToList<T_VIEW_CIM>(tb);
                return t_view_cims[0];
            }
            else
            {

                return null;
            }
        }

        internal static string Get镀铝锌报工guid(string 投入卷号)
        {
            string sql;

            string 查询投入卷号1 = "PHS" + 投入卷号.Replace("PHS", "");
            string 查询投入卷号2 = "PHY" + 投入卷号.Replace("PHY", "");
            sql = " select top 1  guid from Bus_ZincOriginal where (OriginalVolumeNew ='" + 查询投入卷号1 + "' or OriginalVolumeNew ='" + 查询投入卷号2 + "')";
            sql += " order by CreateDate desc  ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                return tb.Rows[0]["guid"].ToString();
            }
            else
            {
                //产生一次
                string guid = Guid.NewGuid().ToString();
                sql = "insert into Bus_LvZincOriginal( guid, WorkShopGuid, WorkShopCode, OriginalVolume, OriginalVolumeNew, OriginalSize,   ";
                sql += " OriginalMaterial, OriginalWeight,OriginalMeter,  PlanSize,OriginalAddress,  CreateID, Creator, CreateDate, IsClosed ) ";
                sql += " select top 1 '" + guid + "',WorkShopGuid ,工厂编号,'',卷号,规格型号,材质,重量,米数,计划产出规格,产地,";
                sql += " '" + pub.sys_user.User_Id + "','" + pub.sys_user.UserTrueName + "',getdate(),'N'   from View_已酸洗轧硬未镀铝锌 ";
                sql += " where  (卷号 ='" + 查询投入卷号1 + "' or 卷号 ='" + 查询投入卷号2 + "') order by 时间 desc  ";
                if (pub.ExecuteSql(pub.ConnectionString, sql, "轧硬报工投入卷信息塞入Bus_LvZincOriginal") > 0)
                {
                    //二次加工给 Bus_ZincOriginal 填上客户，和锌层厚度
                    //先看轧硬卷号的客户，如果有，就结束
                    //string 客户;
                    //客户 = pub.Get客户(投入卷号, "镀锌");
                    //string 锌层厚度;
                    //锌层厚度= pub.Get锌层厚度(投入卷号, "镀锌");

                    return guid;
                }
                else
                {
                    return "";
                }

            }
        }

        public static void FromSize(string 规格型号, out string 厚度, out string 宽度, out string 虚拟值)
        {
            try
            {
                string[] gg = 规格型号.Split("*");
                厚度 = gg[0];
                宽度 = gg[1];
                虚拟值 = gg[2];
            }
            catch
            {
                厚度 = "";
                宽度 = "";
                虚拟值 = "";
            }
        }

        internal static void ListInventoryClass(UIDataGridView uiDataGridViewInventoryClass, string t_good_type)

        {
            string sql;
            sql = "select distinct T_GOOD_TYPE_CODE,T_GOOD_TYPE from T_VIEW_CIM  where 1=1 ";
            if (t_good_type != "")
            {
                sql += " and T_GOOD_TYPE='" + t_good_type + "'";
            }
            sql += "  order  by T_GOOD_TYPE_CODE";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            uiDataGridViewInventoryClass.AutoGenerateColumns = false;
            uiDataGridViewInventoryClass.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            uiDataGridViewInventoryClass.DataSource = tb;
            uiDataGridViewInventoryClass.Refresh();
        }

        public static string Sys_Url = ConfigHelper.GetAppConfig("Sys_Url");
        internal static void ListGoods(UIComboBox uiComboBoxGoods)
        {
            string sql;
            sql = "select distinct t_good_code, t_good_code+' '+t_good_name +' '+t_good_model goods  FROM      T_VIEW_CON order by t_good_code";

            DataTable tb = new DataTable();
            tb = pub.GetDataTable(pub.ConnectionString, sql);
            DataRow dr = tb.NewRow();
            dr["goods"] = "全部 ";
            tb.Rows.InsertAt(dr, 0);
            uiComboBoxGoods.DataSource = tb;
            uiComboBoxGoods.DisplayMember = "t_app_user_name";
            uiComboBoxGoods.ValueMember = "goods";
            uiComboBoxGoods.Refresh();
        }
        /// <summary>
        /// 材质初始化
        /// </summary>
        /// <param name="uiComboBox材质1"></param>
        /// <exception cref="NotImplementedException"></exception>
        internal static void ListSteel(UIComboBox uiComboBox材质1)
        {
            string sql;
            sql = @"SELECT    guid, SteelCode, SteelName, AuditDate, AuditStatus, AuditId, Auditor, Remark, CreateID, Creator, CreateDate, 
                ModifyID, Modifier, ModifyDate
FROM      Dic_SteelType  ";
            DataTable tb = new DataTable();
            tb = pub.GetDataTable(pub.ConnectionString, sql);

            uiComboBox材质1.DataSource = tb;
            uiComboBox材质1.DisplayMember = "SteelName";
            uiComboBox材质1.ValueMember = "SteelCode";
            uiComboBox材质1.Refresh();
        }

        internal static void ListSteelAll(UIComboBox uiComboBox材质)
        {
            string sql;
            sql = @"SELECT    guid, SteelCode, SteelName, AuditDate, AuditStatus, AuditId, Auditor, Remark, CreateID, Creator, CreateDate, 
                ModifyID, Modifier, ModifyDate
FROM      Dic_SteelType  ";
            DataTable tb = new DataTable();
            tb = pub.GetDataTable(pub.ConnectionString, sql);

            DataRow dr = tb.NewRow();
            dr["SteelCode"] = "全部";
            dr["SteelName"] = "全部";
            tb.Rows.InsertAt(dr, 0);

            uiComboBox材质.DataSource = tb;
            uiComboBox材质.DisplayMember = "SteelName";
            uiComboBox材质.ValueMember = "SteelCode";
            uiComboBox材质.Refresh();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="uiComboBox仓库编号"></param>
        /// <param name="workShopGuid"></param>
        internal static void ListWareHouse(UIComboBox uiComboBox仓库编号, string workShopGuid)
        {
            string sql;

            sql = "select guid,WarehouseName Warehouse,WarehouseCode from Dic_Warehouse where 1=1  and workShopGuid='" + workShopGuid + "' ";
            DataTable tb = new DataTable();
            tb = pub.GetDataTable(pub.ConnectionString, sql);
            uiComboBox仓库编号.DataSource = tb;
            uiComboBox仓库编号.DisplayMember = "Warehouse";
            uiComboBox仓库编号.ValueMember = "WarehouseCode";
            uiComboBox仓库编号.Refresh();
        }
        internal static void ListWareHouseALL(UIComboBox uiComboBox仓库编号, string WorkShopCode)
        {
            string sql;

            sql = "select guid,WarehouseCode+' '+ WarehouseName Warehouse,WarehouseCode from Dic_Warehouse where 1=1  and WorkShopCode='" + WorkShopCode + "' ";
            DataTable tb = new DataTable();
            tb = pub.GetDataTable(pub.ConnectionString, sql);
            DataRow dr = tb.NewRow();
            dr["Warehouse"] = "全部";
            dr["Warehouse"] = "全部";
            tb.Rows.InsertAt(dr, 0);
            uiComboBox仓库编号.DataSource = tb;
            uiComboBox仓库编号.DisplayMember = "Warehouse";
            uiComboBox仓库编号.ValueMember = "WarehouseCode";
            uiComboBox仓库编号.Refresh();
        }

        internal static void ListAppUserName(UIComboBox uiComboBox申请人)
        {
            string sql;
            sql = "select distinct t_app_user_code, t_app_user_name FROM      T_VIEW_CON order by t_app_user_name";
            // if (sys_user.UserName== "admin")
            //{

            //}
            DataTable tb = new DataTable();
            tb = pub.GetDataTable(pub.ConnectionString, sql);
            DataRow dr = tb.NewRow();
            dr["T_APP_USER_NAME"] = "全部 ";
            tb.Rows.InsertAt(dr, 0);
            uiComboBox申请人.DataSource = tb;
            uiComboBox申请人.DisplayMember = "t_app_user_name";
            uiComboBox申请人.ValueMember = "t_app_user_code";
            uiComboBox申请人.Refresh();
        }

        public static string Sys_User_getVierificationCode = ConfigHelper.GetAppConfig("Sys_User_getVierificationCode");
        /// <summary>
        /// 合同类型初始化
        /// </summary>
        /// <param name="uiComboBox合同类型"></param>
        /// <exception cref="NotImplementedException"></exception>
        internal static void ListContractType(UIComboBox uiComboBox合同类型)
        {
            string sql;
            sql = "select distinct t_contract_type_cid, t_contract_type_name FROM      T_VIEW_CON";
            // if (sys_user.UserName== "admin")
            //{

            //}
            DataTable tb = new DataTable();
            tb = pub.GetDataTable(pub.ConnectionString, sql);
            uiComboBox合同类型.DataSource = tb;
            uiComboBox合同类型.DisplayMember = "t_contract_type_name";
            uiComboBox合同类型.ValueMember = "t_contract_type_cid";
            uiComboBox合同类型.Refresh();
        }

        public static List<Dic_WorkShop> CanViewWorkShops;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cid"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        internal static T_VIEW_CON GetT_VIEW_CON(string cid)
        {
            string sql;
            sql = @"SELECT  guid, CID, T_APP_DPT_CID, T_APP_DPT_NAME, T_APP_USER_CODE, T_APP_USER_NAME, 
                T_APP_USER_TEL, T_APP_USER_DATE, T_EXECUTOR_NAME, T_EXECUTOR_CODE, EXP40, T_DRAFT_NAME, 
                T_RELATED_NAME, T_RELATED_CID, T_CONTRACT_CODE, T_CONTRACT_NAME, T_CONTRACT_TYPE_NAME, 
                T_CONTRACT_TYPE_CID, T_CONTRACT_MONEY, T_MONEY_UNIT, T_MONEY_CAPITAILZATION, T_RATE, 
                T_RATE_BEFOR_MONEY, T_TEAN_TYPE, T_START_DATE, T_END_DATE, T_TEAN, T_TEAN_UNIT, T_PAY_WAY, 
                T_PAY_WAY_CID, T_PROJECT_NAME, T_PROJECT_CID, T_PROJECT_USER_NAME, T_PROJECT_USER_CODE, 
                T_REMARK, T_SUBJECT_NAME, T_SUBJECT_CID, T_SEAL, T_SEAL_PATH, T_GOOD_CID, T_ORDER, T_GOOD_CODE, 
                T_GOOD_NAME, T_GOOD_MODEL, T_GOOD_PRICE, T_GOOD_NUM, T_GOOD_UNIT, T_GOOD_MONEY, T_GOOD_TIME, 
                T_GOOD_ADDRESS, T_GOOD_REMARK, T_GOOD_TRANSACTION_NUM, T_GOOD_EXP1, T_GOOD_EXP2, 
                T_GOOD_EXP3, T_GOOD_EXP4, T_RELATIVE_NAME 
FROM      T_VIEW_CON   where cid='" + cid + "'";

            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null)
            {
                List<T_VIEW_CON> t_view_cons = pub.GetTableToList<T_VIEW_CON>(tb);
                return t_view_cons[0];
            }
            else
            {
                //T_VIEW_CON t_view_con = new T_VIEW_CON();
                return null;
            }




        }
        public static List<T> GetTableToList<T>(this DataTable dt)
        {
            var list = new List<T>();
            var plist = new List<PropertyInfo>(typeof(T).GetProperties());
            foreach (DataRow item in dt.Rows)
            {
                T s = Activator.CreateInstance<T>();
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    PropertyInfo info = plist.Find(p => p.Name == dt.Columns[i].ColumnName);
                    if (info != null)
                    {
                        try
                        {
                            if (!Convert.IsDBNull(item[i]))
                            {
                                object v = null;
                                if (info.PropertyType.ToString().Contains("System.Nullable"))
                                {
                                    v = Convert.ChangeType(item[i], Nullable.GetUnderlyingType(info.PropertyType));
                                }
                                else
                                {
                                    v = Convert.ChangeType(item[i], info.PropertyType);
                                }
                                info.SetValue(s, v, null);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("字段[" + info.Name + "]转换出错," + ex.Message);
                        }
                    }
                }
                list.Add(s);
            }
            return list;
        }


        /// <summary>
        /// List集合转DataTable
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="list">传入集合</param>
        /// <returns>返回datatable结果</returns>
        public static DataTable GetListToTable<T>(List<T> list)
        {
            Type tp = typeof(T);
            PropertyInfo[] proInfos = tp.GetProperties();
            DataTable dt = new DataTable();
            foreach (var item in proInfos)
            {
                dt.Columns.Add(item.Name, item.PropertyType); //添加列名及对应类型
            }
            foreach (var item in list)
            {
                DataRow dr = dt.NewRow();
                foreach (var proInfo in proInfos)
                {
                    object obj = proInfo.GetValue(item);
                    if (obj == null)
                    {
                        continue;
                    }
                    dr[proInfo.Name] = obj;
                }
                dt.Rows.Add(dr);
            }
            return dt;
        }
        /// <summary>
        /// 是否存在原料卷号
        /// </summary>
        /// <param name="原料卷号"></param>
        /// <returns></returns>
        internal static bool IsExistVolume(string 原料卷号)
        {
            string sql;
            sql = "select VolumeCode from Bus_StockInVolume where VolumeCode='" + 原料卷号 + "' and left (DocCode,4)='YLRK'";
            //sql += " union all ";
            //sql += " select VolumeCode from Bus_Volume where VolumeCode='" + 原料卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }



        /// <summary>
        /// 显示当前用户可以访问的工厂信息
        /// </summary>
        /// <param name="sys_user"></param>
        /// <param name="uiComboBoxWorkShop"></param>
        /// <exception cref="NotImplementedException"></exception>
        internal static void ListWorkShop(Sys_User sys_user, UIComboBox uiComboBoxWorkShop)
        {
            string sql;
            sql = "select WorkShopCode, WorkShopName  FROM      Dic_WorkShop where WorkShopCode='1001' ";
            // if (sys_user.UserName== "admin")
            //{

            //}
            DataTable dtWorkShop = new DataTable();
            dtWorkShop = pub.GetDataTable(pub.ConnectionString, sql);
            uiComboBoxWorkShop.DataSource = dtWorkShop;
            uiComboBoxWorkShop.DisplayMember = "WorkShopName";
            uiComboBoxWorkShop.ValueMember = "WorkShopCode";
            uiComboBoxWorkShop.Refresh();
        }
        /// <summary>
        /// 检查规格型号
        /// </summary>
        /// <param name="规格型号">0.000*0.0*C</param>
        /// <returns>false不符合规格型号，true符合规格型号</returns>
        /// <exception cref="NotImplementedException"></exception>
        internal static bool CheckSize(string 规格型号)
        {
            bool flag = false;
            try
            {
                string[] s;
                int k;
                s = 规格型号.Split("*");
                if (s.Length == 3)
                {
                    if (pub.Todecimal(s[0]) > 0 && pub.Todecimal(s[1]) > 0 && s[2].Length == 1)
                    {
                        return true;
                    }
                    else
                    {
                        return flag;
                    }

                }
                else
                {
                    return flag;
                }
            }
            catch
            {
                return flag;
            }


        }

        internal static string getMac()
        {
            return getIP.getLocalMac();
        }

        public static Sys_User sys_user;
        



        //public static string ConnectionString = ConfigHelper.GetAppConfig("ConnectionString");
        //public static string ConnectionString = ConfigHelper.GetAppConfig("ConnectionString");


        public static DataTable GetDataTable(string ConnectionString, string mysql)
        {
            try
            {
                mysql = mysql.Replace("--", "");
                DataSet ds = new DataSet();
                SqlConnection m_myConnection = new SqlConnection(ConnectionString);
                m_myConnection.Open();
                SqlCommand cmd = new SqlCommand(mysql, m_myConnection);
                cmd.CommandTimeout = 1000000;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(ds);
                m_myConnection.Close();
                m_myConnection.Dispose();
                return ds.Tables[0];


            }
            catch
            {
                return null;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xmlData"></param>
        /// <returns></returns>
        public static DataTable ConvertXMLToDataTable(string xmlData)
        {
            TextReader sr = null;
            try
            {
                DataTable dt = new DataTable();
                sr = new StringReader(xmlData);
                dt.ReadXml(sr);
                return dt;
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (sr != null) sr.Close();
            }
        }

        internal static Sys_User GetUserByUserName(string userName)
        {
            Sys_User sys_user = new Sys_User();
            string sql;
            sql = @"select  User_Id, Address, AppType, AuditDate, AuditStatus, Auditor, CreateDate, CreateID, Creator, DeptName, 
                Dept_Id, Email, Enable, Gender, HeadImageUrl, IsRegregisterPhone, LastLoginDate, LastModifyPwdDate, Mobile, 
                Modifier, ModifyDate, ModifyID, OrderNo, Role_Id, RoleName, PhoneNo, Remark, Tel, UserName, UserPwd, 
                UserTrueName, Token 
FROM      Sys_User where UserName= '" + userName + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null)
            {
                if (tb.Rows.Count > 0)
                {
                    sys_user.User_Id = pub.ToInt(tb.Rows[0]["User_Id"].ToString());
                    sys_user.Address = tb.Rows[0]["Address"].ToString();
                    sys_user.AppType = pub.ToInt(tb.Rows[0]["AppType"].ToString());
                    sys_user.AuditDate = pub.ToDate(tb.Rows[0]["AuditDate"].ToString());
                    sys_user.AuditStatus = pub.ToInt(tb.Rows[0]["AuditStatus"].ToString());
                    sys_user.Auditor = tb.Rows[0]["Auditor"].ToString();
                    sys_user.CreateDate = pub.ToDate(tb.Rows[0]["CreateDate"].ToString());
                    sys_user.CreateID = pub.ToInt(tb.Rows[0]["CreateID"].ToString());
                    sys_user.Creator = tb.Rows[0]["Creator"].ToString();
                    sys_user.DeptName = tb.Rows[0]["DeptName"].ToString();
                    sys_user.Dept_Id = pub.ToInt(tb.Rows[0]["Dept_Id"].ToString());
                    sys_user.Email = tb.Rows[0]["Email"].ToString();
                    sys_user.Enable = pub.ToByte(tb.Rows[0]["Enable"].ToString());
                    sys_user.Gender = pub.ToInt(tb.Rows[0]["Gender"].ToString());
                    sys_user.HeadImageUrl = tb.Rows[0]["HeadImageUrl"].ToString();
                    sys_user.IsRegregisterPhone = pub.ToInt(tb.Rows[0]["IsRegregisterPhone"].ToString());
                    sys_user.LastLoginDate = pub.ToDate(tb.Rows[0]["LastLoginDate"].ToString());
                    sys_user.LastModifyPwdDate = pub.ToDate(tb.Rows[0]["LastModifyPwdDate"].ToString());
                    sys_user.Mobile = tb.Rows[0]["Mobile"].ToString();
                    sys_user.Modifier = tb.Rows[0]["Modifier"].ToString();
                    sys_user.ModifyDate = pub.ToDate(tb.Rows[0]["ModifyDate"].ToString());
                    sys_user.ModifyID = pub.ToInt(tb.Rows[0]["ModifyID"].ToString());
                    sys_user.OrderNo = pub.ToInt(tb.Rows[0]["OrderNo"].ToString());
                    sys_user.Role_Id = pub.ToInt(tb.Rows[0]["Role_Id"].ToString());
                    sys_user.RoleName = tb.Rows[0]["RoleName"].ToString();
                    sys_user.PhoneNo = tb.Rows[0]["PhoneNo"].ToString();
                    sys_user.Remark = tb.Rows[0]["Remark"].ToString();
                    sys_user.Tel = tb.Rows[0]["Tel"].ToString();
                    sys_user.UserName = tb.Rows[0]["UserName"].ToString();
                    sys_user.UserPwd = tb.Rows[0]["UserPwd"].ToString();
                    sys_user.UserTrueName = tb.Rows[0]["UserTrueName"].ToString();
                    sys_user.Token = tb.Rows[0]["Token"].ToString();
                    return sys_user;
                }
                else
                {
                    return null;
                }

            }
            else
            {
                return null;
            }

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="部门编号"></param>
        /// <param name="工厂编号"></param>
        /// <returns></returns>
        internal static Dic_Depart GetDepartByCode(string 部门编号, string 工厂编号)
        {
            string sql;
            string workShopGuid = GetWorkShopByCode(工厂编号).guid.ToString();
            sql = @"SELECT    guid, WorkShopGuid, DepartCode, DepartName, ParentGuid, NcCode, AuditDate, AuditStatus, AuditId, Auditor, 
                Remark, CreateID, Creator, CreateDate, ModifyID, Modifier, ModifyDate
FROM      Dic_Depart where DepartCode='" + 部门编号 + "' and WorkShopGuid='" + workShopGuid + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null && tb.Rows.Count > 0)
            {
                List<Dic_Depart> dic_depart = pub.GetTableToList<Dic_Depart>(tb);
                return dic_depart[0];
            }
            else
            {
                Dic_Depart dic_depart = new Dic_Depart();
                return dic_depart;
            }
        }

        internal static bool 彩涂符合万都理算厚度(decimal 成品厚度, decimal 理算厚度)
        {
            decimal 计算厚度 = pub.Todecimal(Get彩涂万都厚度(理算厚度));
            decimal 厚度 = pub.Todecimal(成品厚度);
            if (计算厚度 == 厚度)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        private static string Get彩涂万都厚度(decimal 厚度)
        {
            string sql;
            string 计算厚度;
            sql = "SELECT    计算厚度 FROM      Cal_WanduThick where 厚度下限<='" + 厚度 + "' and 厚度上限>='" + 厚度 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                计算厚度 = tb.Rows[0]["计算厚度"].ToString();
                return 计算厚度.ToString();
            }
            else
            {
                return "";
            }
        }

        internal static bool 彩涂符合万达理算厚度(decimal 成品厚度, decimal 理算厚度)
        {
            decimal 计算厚度 = pub.Todecimal(Get彩涂万达厚度(理算厚度));
            decimal 厚度 = pub.Todecimal(成品厚度);
            if (计算厚度 == 厚度)
            {
                return true;
            }
            else
            {
                return false;
            }

        }

        private static string Get彩涂万达厚度(decimal 厚度)
        {
            string sql;
            string 计算厚度;
            sql = "SELECT    计算厚度 FROM      Cal_PaintThick where 厚度下限<='" + 厚度 + "' and 厚度上限>='" + 厚度 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                计算厚度 = tb.Rows[0]["计算厚度"].ToString();
                return 计算厚度.ToString();
            }
            else
            {
                return "";
            }
        }

        /// <summary>
        /// 单据编号
        /// </summary>
        /// <param name="typeName">单据类型</param>
        /// <param name="workShopCode">工厂编号</param>
        /// <returns>单据类型-工厂编号-业务日期-5位串码</returns>
        internal static string GetDocCode(string typeName, string workShopCode)
        {
            string sql;
            sql = @"SELECT    guid, TypeName, TypeCode, TableName, FieldName, CreateID, Creator, CreateDate, ModifyID, Modifier, 
                ModifyDate, ApproverID, Approver, ApproverDate ,replace (convert(varchar(10),getdate(),21),'-','') CurrentDate
FROM      Sys_CodeRole where TypeName='" + typeName + "' ";
            string tableName;
            string fieldName;
            string leftCode;
            string currentDate;
            int leftCodeLenth;
            int currentNumber;
            int nextNumber;
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                tableName = tb.Rows[0]["TableName"].ToString();
                fieldName = tb.Rows[0]["FieldName"].ToString();
                currentDate = tb.Rows[0]["CurrentDate"].ToString();
                leftCode = tb.Rows[0]["TypeCode"].ToString() + "-" + workShopCode + "-" + currentDate;  ///左边前缀

                leftCodeLenth = leftCode.Length;

                sql = "select isnull( max(substring(" + fieldName + "," + (leftCodeLenth + 2) + ",10)),0) maxcode from " + tableName + " where substring(" + fieldName + ",1," + leftCodeLenth + ")='" + leftCode + "'";
                DataTable tb2 = pub.GetDataTable(pub.ConnectionString, sql);
                if (tb2.Rows.Count > 0)
                {
                    currentNumber = pub.ToInt(tb2.Rows[0]["maxcode"].ToString());
                    if (currentNumber != 0)
                    {
                        nextNumber = currentNumber + 1;
                        return leftCode + "-" + nextNumber.ToString().PadLeft(5, '0');

                    }
                    else
                    {
                        return leftCode + "-" + "00001";
                    }
                }

                else
                {
                    return "";
                }
            }
            else
            {
                return "";
            }


        }
        /// <summary>
        /// 根据工厂guid得到工厂对象
        /// </summary>
        /// <param name="WorkShopGuid">工厂guid</param>
        /// <returns>Dic_WorkShop</returns>
        internal static Dic_WorkShop GetWorkShopById(string WorkShopGuid)
        {
            string sql;
            sql = @"SELECT   guid, WorkShopCode, WorkShopName, AuditDate, AuditStatus, AuditId, Auditor, Remark, CreateID, Creator, 
                CreateDate, ModifyID, Modifier, ModifyDate 
FROM      Dic_WorkShop where guid='" + WorkShopGuid + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null)
            {
                List<Dic_WorkShop> dic_workshop = pub.GetTableToList<Dic_WorkShop>(tb);
                return dic_workshop[0];
            }
            else
            {
                Dic_WorkShop dic_workshop = new Dic_WorkShop();
                return dic_workshop;
            }

        }

        internal static Bus_PicklingOriginal Get酸洗投入信息(string WorkShopCode,string VolumeCodeNew)
        {
            string sql;
            sql = @"SELECT    guid, WorkShopGuid, WorkShopCode, OriginalVolume, OriginalVolumeNew, OriginalSize, OriginalWeight, 
                   OriginalMaterial, PlanSize, CreateID, Creator, CreateDate, ModifyID, Modifier, ModifyDate, IsClosed, ColseUserId, 
                   ColseUserName, CloseDate
FROM      Bus_PicklingOriginal where WorkShopCode='"+ WorkShopCode + "' and OriginalVolumeNew='" + VolumeCodeNew + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null)
            {
                List<Bus_PicklingOriginal> bus_pickling_originals = pub.GetTableToList<Bus_PicklingOriginal>(tb);
                return bus_pickling_originals[0];
            }
            else
            {
                
                return null;
            }
        }

        internal static Dic_WorkShop GetWorkShopByCode(string WorkShopCode)
        {
            string sql;
            sql = @"SELECT   guid, WorkShopCode, WorkShopName, AuditDate, AuditStatus, AuditId, Auditor, Remark, CreateID, Creator, 
                CreateDate, ModifyID, Modifier, ModifyDate 
FROM      Dic_WorkShop where WorkShopCode='1001'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null)
            {
                List<Dic_WorkShop> dic_workshop = pub.GetTableToList<Dic_WorkShop>(tb);
                return dic_workshop[0];
            }
            else
            {
                Dic_WorkShop dic_workshop = new Dic_WorkShop();
                return dic_workshop;
            }

        }

        /// <summary>
        /// 根据工厂显示库位
        /// </summary>
        /// <param name="uiComboBox入库库位"></param>
        /// <param name="工厂编号"></param>
        /// <param name="仓库编号"></param>
        internal static void ListLocation(UIComboBox uiComboBox入库库位, string 工厂编号, string 库位搜索, string 仓库编号)
        {
            string sql;
            sql = @"SELECT   dbo.Dic_Location.LocationCode, dbo.Dic_WorkShop.WorkShopCode, dbo.Dic_Warehouse.WarehouseCode
FROM      dbo.Dic_Location INNER JOIN
                dbo.Dic_Warehouse ON dbo.Dic_Location.WarehouseGuid = dbo.Dic_Warehouse.guid INNER JOIN
                dbo.Dic_WorkShop ON dbo.Dic_Warehouse.WorkShopGuid = dbo.Dic_WorkShop.guid  where dbo.Dic_WorkShop.WorkShopCode='" + 工厂编号 + "' and  dbo.Dic_Warehouse.WarehouseCode='" + 仓库编号 + "'";
            if (库位搜索.Replace("--", "") != "")
            {
                sql += " and  dbo.Dic_Location.LocationCode like '%" + 库位搜索 + "%'";
            }
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null)
            {
                uiComboBox入库库位.DataSource = tb;
                uiComboBox入库库位.ValueMember = "LocationCode";
                uiComboBox入库库位.DisplayMember = "LocationCode";
                uiComboBox入库库位.Refresh();
            }
            else
            {
                uiComboBox入库库位.DataSource = null;

                uiComboBox入库库位.Refresh();

            }
        }
        internal static void ListLocationAll(UIComboBox uiComboBox入库库位, string 工厂编号, string 库位搜索, string 仓库编号)
        {
            string sql;
            sql = @"SELECT   dbo.Dic_Location.LocationCode, dbo.Dic_WorkShop.WorkShopCode, dbo.Dic_Warehouse.WarehouseCode
FROM      dbo.Dic_Location INNER JOIN
                dbo.Dic_Warehouse ON dbo.Dic_Location.WarehouseGuid = dbo.Dic_Warehouse.guid INNER JOIN
                dbo.Dic_WorkShop ON dbo.Dic_Warehouse.WorkShopGuid = dbo.Dic_WorkShop.guid  where dbo.Dic_WorkShop.WorkShopCode='" + 工厂编号 + "' and  dbo.Dic_Warehouse.WarehouseCode='" + 仓库编号 + "'";
            if (库位搜索.Replace("--", "") != "")
            {
                sql += " and  dbo.Dic_Location.LocationCode like '%" + 库位搜索 + "%'";
            }
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null)
            {
                uiComboBox入库库位.DataSource = tb;
                uiComboBox入库库位.ValueMember = "LocationCode";
                uiComboBox入库库位.DisplayMember = "LocationCode";
                uiComboBox入库库位.Refresh();
            }
            else
            {
                uiComboBox入库库位.DataSource = null;

                uiComboBox入库库位.Refresh();

            }
        }

        //        internal static void ListDepartments(string 工厂编号, UIComboBox uiComboBox部门1)
        //        {
        //            string sql;
        //            sql = @"SELECT   guid, WorkShopGuid, DepartCode, DepartName, ParentGuid, NcCode, AuditDate, AuditStatus, AuditId, Auditor, 
        //                Remark, CreateID, Creator, CreateDate, ModifyID, Modifier, ModifyDate
        //FROM      Dic_Depart   where ";

        //        }

        private static byte ToByte(string v)
        {
            try
            {
                return byte.Parse(v);
            }
            catch
            { return 0; }
        }

        public static string HttpGet(string strURL)
        {

            System.Net.HttpWebRequest request;
            // 创建一个HTTP请求
            request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
            //request.Method="get";
            System.Net.HttpWebResponse response;
            response = (System.Net.HttpWebResponse)request.GetResponse();
            System.IO.StreamReader myreader = new System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8);
            string responseText = myreader.ReadToEnd();
            myreader.Close();
            return responseText;
        }

        public static string HttpPost(string strURL, string postJson)
        {

            System.Net.HttpWebRequest request;
            request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
            //Post请求方式
            request.Method = "POST";
            // 内容类型
            request.ContentType = "application/json-patch+json";
            if (sys_user != null)
            {
                // request.Headers.Add("Authoriztion", sys_user.Token);
                request.Headers.Set("Authorization", "Bearer " + sys_user.Token);

            }
            // 参数经过URL编码
            byte[] byteData;
            //将URL编码后的字符串转化为字节
            byteData = System.Text.Encoding.UTF8.GetBytes(postJson);
            //设置请求的 ContentLength 
            request.ContentLength = byteData.Length;
            //获得请 求流
            System.IO.Stream writer = request.GetRequestStream();
            //将请求参数写入流
            writer.Write(byteData, 0, byteData.Length);
            // 关闭请求流
            writer.Close();
            System.Net.HttpWebResponse response;
            // 获得响应流
            response = (System.Net.HttpWebResponse)request.GetResponse();
            System.IO.StreamReader myreader = new System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8);
            string responseText = myreader.ReadToEnd();
            myreader.Close();
            // MessageBox.Show(responseText);
            return responseText;
        }
        public static string HttpPost(string strURL)
        {

            System.Net.HttpWebRequest request;
            request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
            //Post请求方式
            request.Method = "POST";
            // 内容类型
            request.ContentType = "application/json-patch+json";
            if (sys_user != null)
            {
                // request.Headers.Add("Authoriztion", sys_user.Token);
                request.Headers.Set("Authorization", "Bearer " + sys_user.Token);

            }
            // 参数经过URL编码
            //byte[] byteData;
            //将URL编码后的字符串转化为字节
            // byteData = System.Text.Encoding.UTF8.GetBytes(postJson);
            //设置请求的 ContentLength 
            // request.ContentLength = byteData.Length;
            //获得请 求流
            System.IO.Stream writer = request.GetRequestStream();
            //将请求参数写入流
            //writer.Write(byteData, 0, byteData.Length);
            // 关闭请求流
            writer.Close();
            System.Net.HttpWebResponse response;
            // 获得响应流
            response = (System.Net.HttpWebResponse)request.GetResponse();
            System.IO.StreamReader myreader = new System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8);
            string responseText = myreader.ReadToEnd();
            myreader.Close();
            // MessageBox.Show(responseText);
            return responseText;
        }
        public static string HttpPostForm(string strURL, string postJson)
        {

            System.Net.HttpWebRequest request;
            request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
            //Post请求方式
            request.Method = "POST";
            // 内容类型
            request.ContentType = "application/x-www-form-urlencoded";
            if (sys_user != null)
            {
                // request.Headers.Add("Authoriztion", sys_user.Token);
                request.Headers.Set("Authorization", "Bearer " + sys_user.Token);

            }
            // 参数经过URL编码
            byte[] byteData;
            //将URL编码后的字符串转化为字节
            byteData = System.Text.Encoding.UTF8.GetBytes(postJson);
            //设置请求的 ContentLength 
            request.ContentLength = byteData.Length;
            //获得请 求流
            System.IO.Stream writer = request.GetRequestStream();
            //将请求参数写入流
            writer.Write(byteData, 0, byteData.Length);
            // 关闭请求流
            writer.Close();
            System.Net.HttpWebResponse response;
            // 获得响应流
            response = (System.Net.HttpWebResponse)request.GetResponse();
            System.IO.StreamReader myreader = new System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8);
            string responseText = myreader.ReadToEnd();
            myreader.Close();
            // MessageBox.Show(responseText);
            return responseText;
        }

        public static string HttpPost(string url, string paramData, Dictionary<string, string> headers = null, string contentType = "application/json", int timeOut = 30)
        {
            using (HttpClient client = new HttpClient())
            {
                if (headers != null)
                {
                    foreach (var header in headers)
                        client.DefaultRequestHeaders.Add(header.Key, header.Value);
                }
                using (HttpContent httpContent = new StringContent(paramData, Encoding.UTF8))
                {
                    if (contentType != null)
                        httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
                    HttpResponseMessage response = client.PostAsync(url, httpContent).Result;
                    return response.Content.ReadAsStringAsync().Result;
                }
            }
        }





        internal static int ToInt(object p)
        {
            try
            {
                if (p.ToString() == "")
                {
                    return 0;
                }
                return int.Parse(p.ToString());
            }
            catch
            {
                return 0;
            }
        }
        /// <summary>
        /// 执行sql语句
        /// </summary>
        /// <param name="ConnectionString"></param>
        /// <param name="mysql"></param>
        /// <returns></returns>
        public static int ExecuteSql(string ConnectionString, string mysql)
        {

            try
            {
                mysql = mysql.Replace("--", "");
                int result;
                SqlConnection m_myConnection = new SqlConnection(ConnectionString);
                m_myConnection.Open();
                SqlCommand cmd = new SqlCommand(mysql, m_myConnection);
                cmd.CommandTimeout = 1000000;
                cmd.CommandText = mysql;
                result = cmd.ExecuteNonQuery();
                m_myConnection.Close();
                m_myConnection.Dispose();
                return result;
            }
            catch
            {
                return 0;
            }

        }
        internal static int ExecuteSql(string ConnectionString, string mysql, string msg)
        {

            try
            {
                string logsql = @"insert into Sys_Log( BeginDate, BrowserType, RequestParameter,UserName, User_Id ,UserIP   )";
                string RequestParameter = mysql.Replace("'", "''");
                logsql += "values(getdate(),'WinForm','" + RequestParameter + "','" + sys_user.UserName + "','" + sys_user.User_Id + "','" + MAC.getIP.getLocalIP() + "')";
                ExecuteSql(ConnectionString, logsql);
                int result;
                SqlConnection m_myConnection = new SqlConnection(ConnectionString);
                m_myConnection.Open();
                SqlCommand cmd = new SqlCommand(mysql, m_myConnection);
                cmd.CommandTimeout = 1000000;
                cmd.CommandText = mysql;
                result = cmd.ExecuteNonQuery();
                m_myConnection.Close();
                m_myConnection.Dispose();
                return result;
            }
            catch
            {
                return 0;
            }

        }
        //internal static int ExecuteUpdateSql(string ConnectionString, string mysql, string msg)
        //{

        //    try
        //    {
        //        string logsql = @"insert into Sys_Log( BeginDate, BrowserType, RequestParameter,UserName, User_Id ,UserIP   )";
        //        string RequestParameter = mysql.Replace("'", "''");
        //        logsql += "values(getdate(),'WinForm','" + RequestParameter + "','" + sys_user.UserName + "','" + sys_user.User_Id + "','" + MAC.getIP.getLocalIP() + "')";
        //        ExecuteSql(ConnectionString, logsql);
        //        int result;
        //        SqlConnection m_myConnection = new SqlConnection(ConnectionString);
        //        m_myConnection.Open();
        //        SqlCommand cmd = new SqlCommand(mysql, m_myConnection);
        //        cmd.CommandTimeout = 1000000;
        //        cmd.CommandText = mysql;
        //        result = cmd.ExecuteNonQuery();
        //        m_myConnection.Close();
        //        m_myConnection.Dispose();
        //        return result;
        //    }
        //    catch
        //    {
        //        return 0;
        //    }

        //}

        public static void kill(Microsoft.Office.Interop.Excel.Application excel)
        {
            IntPtr t = new IntPtr(excel.Hwnd);//得到这个句柄，具体作用是得到这块内存入口 

            int k = 0;
            GetWindowThreadProcessId(t, out k);   //得到本进程唯一标志k
            System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(k);   //得到对进程k的引用
            p.Kill();     //关闭进程k

        }
        public static bool DataGridviewShowToExcel(DataGridView dgv, bool isShowExcle)
        {
            if (dgv.Rows.Count == 0)
                return false;
            //建立Excel对象    
            Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
            excel.Application.Workbooks.Add(true);
            excel.Visible = isShowExcle;
            //生成字段名称    
            for (int i = 0; i < dgv.ColumnCount; i++)
            {
                excel.Cells[1, i + 1] = dgv.Columns[i].HeaderText;
            }
            //填充数据    
            for (int i = 0; i < dgv.RowCount; i++)
            {
                for (int j = 0; j < dgv.ColumnCount; j++)
                {
                    if (dgv[j, i].ValueType == typeof(string))
                    {
                        excel.Cells[i + 2, j + 1] = "'" + dgv[j, i].Value.ToString();
                    }
                    else
                    {
                        excel.Cells[i + 2, j + 1] = dgv[j, i].Value.ToString();
                    }
                }
            }
            return true;
        }

        internal static decimal Todecimal(object p)
        {
            try
            {
                return decimal.Parse(p.ToString());
            }
            catch
            {
                return 0;
            }
        }

        internal static DateTime ToDate(string p)
        {
            DateTime dt = new DateTime(2000, 1, 1);
            try
            {
                return DateTime.Parse(p);
            }
            catch
            {
                return dt;
            }
        }




        private static string Getbusinesstype(string 业务类型)
        {
            //string sql;
            //sql = "select cPTCode from PurchaseType where cPTName='" + 业务类型 + "'";
            //DataTable tb = pub.GetDataTable(sql);
            //if (tb.Rows.Count >0)
            //{
            //    return tb.Rows[0][0].ToString();
            //}
            //else
            //{
            //    return "";
            //}
            return 业务类型;
        }
        /// <summary>
        ///     Delete原料入库临时数据
        /// </summary>
        internal static void Delete原料入库临时数据()
        {
            string sql;
            sql = "delete Temp_原料卷入库 where mac ='" + pub.getMac() + "'";
            pub.ExecuteSql(pub.ConnectionString, sql, "删除原料入库临时数据");
        }
        internal static void Delete辅料入库临时数据()
        {
            string sql;
            sql = "delete Temp_辅料入库 where mac ='" + pub.getMac() + "'";
            pub.ExecuteSql(pub.ConnectionString, sql, "删除辅料入库临时数据");
        }

        internal static string getWareHouse(string code_name)
        {
            string sql;
            sql = "select WarehouseCode  from Dic_Warehouse where (WarehouseCode='" + code_name + "' or WarehouseName ='" + code_name + "')";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                return tb.Rows[0][0].ToString();
            }
            else
            {
                return "";
            }
        }
        

        internal static DataTable 直接查询招采平台原料卷存货(string 存货名称, string 规格型号, string 材质)
        {
            string sql;
            sql = @"select [T_GOOD_NAME]        ,[T_GOOD_CODE]            ,[T_GOOD_TYPE]        ,[T_GOOD_TYPE_CODE]            ,[T_GOOD_MODEL]
                ,[T_GOOD_UNIT] from [DASContract].[dbo].[VIEW_CIM] where T_GOOD_NAME='" + 存货名称 + "' and T_GOOD_MODEL='" + 规格型号 +
                "' and T_GOOD_TYPE = '热轧' and T_GOOD_STATUE = '启用' and EXP4='" + 材质 + "'";
            DataTable tb = pub.GetDataTable(pub.purchaseConn, sql);
            return tb;
        }

        internal static string getLocation(string code_name)
        {
            string sql;
            sql = "select LocationCode  from Dic_Location where (LocationCode='" + code_name + "' or LocationDesc ='" + code_name + "')";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                return tb.Rows[0][0].ToString();
            }
            else
            {
                return "";
            }
        }

        internal static T_VIEW_CON GetT_VIEW_CON(string 合同号, string 合同行号)
        {
            string sql;
            sql = @"SELECT  guid, CID, T_APP_DPT_CID, T_APP_DPT_NAME, T_APP_USER_CODE, T_APP_USER_NAME, 
                T_APP_USER_TEL, T_APP_USER_DATE, T_EXECUTOR_NAME, T_EXECUTOR_CODE, EXP40, T_DRAFT_NAME, 
                T_RELATED_NAME, T_RELATED_CID, T_CONTRACT_CODE, T_CONTRACT_NAME, T_CONTRACT_TYPE_NAME, 
                T_CONTRACT_TYPE_CID, T_CONTRACT_MONEY, T_MONEY_UNIT, T_MONEY_CAPITAILZATION, T_RATE, 
                T_RATE_BEFOR_MONEY, T_TEAN_TYPE, T_START_DATE, T_END_DATE, T_TEAN, T_TEAN_UNIT, T_PAY_WAY, 
                T_PAY_WAY_CID, T_PROJECT_NAME, T_PROJECT_CID, T_PROJECT_USER_NAME, T_PROJECT_USER_CODE, 
                T_REMARK, T_SUBJECT_NAME, T_SUBJECT_CID, T_SEAL, T_SEAL_PATH, T_GOOD_CID, T_ORDER, T_GOOD_CODE, 
                T_GOOD_NAME, T_GOOD_MODEL, T_GOOD_PRICE, T_GOOD_NUM, T_GOOD_UNIT, T_GOOD_MONEY, T_GOOD_TIME, 
                T_GOOD_ADDRESS, T_GOOD_REMARK, T_GOOD_TRANSACTION_NUM, T_GOOD_EXP1, T_GOOD_EXP2, 
                T_GOOD_EXP3, T_GOOD_EXP4, T_RELATIVE_NAME 
FROM      T_VIEW_CON   where T_CONTRACT_CODE='" + 合同号 + "' and T_ORDER='" + 合同行号 + "'";

            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null)
            {
                List<T_VIEW_CON> t_view_cons = pub.GetTableToList<T_VIEW_CON>(tb);
                return t_view_cons[0];
            }
            else
            {
                //T_VIEW_CON t_view_con = new T_VIEW_CON();
                return null;
            }
        }

        internal static bool IsVolumeApproved(string volumeCode)
        {
            string sql;
            sql = @"SELECT   StockInType, WorkShopCode, DocCode, DepartCode, CreateID, Creator, CreateDate, ModifyID, 
Modifier, ModifyDate,   ApproverID, Approver, ApproverDate, IsSendToNC, SendToNCDate, RowNumber, WarehouseCode, 
StorageLocation,  T_CONTRACT_CODE, T_ORDER, T_GOOD_UNIT, T_GOOD_NUM, T_GOOD_PRICE, T_GOOD_MONEY, VolumeCode,
VolumeCodeNew, InventoryCode, Size, Thick, Width, Material, Address, Weight, Virtual, CID FROM      View_StockIn ";
            sql += " where VolumeCode='" + volumeCode + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                if (tb.Rows[0]["Approver"].ToString() != "")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        ///   采购入库的卷号
        /// </summary>
        /// <param name="volumeCode">采购入库时的卷号</param>
        /// <returns></returns>
        internal static bool IsPurchaseVolumeBeUsed(string workshopCode, string volumeCode)
        {
            string sql;

            sql = @"SELECT  VolumeCode,VolumeCodeNew  FROM   View_PurchaseVolumeBeUsed ";
            sql += " where (VolumeCode='" + volumeCode + "' or VolumeCodeNew ='" + volumeCode + "') and workshopCode='" + workshopCode + "' ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {

                return true;

            }
            else
            {
                return false;
            }
        }
        internal static bool IsPurchaseVolumeBeUsed(string workshopCode, string volumeCode, string StorageLocation)
        {
            string sql;

            sql = @"SELECT  VolumeCode,VolumeCodeNew  FROM   View_PurchaseVolumeBeUsed ";
            sql += " where (VolumeCode='" + volumeCode + "' or VolumeCodeNew ='" + volumeCode + "') and workshopCode='" + workshopCode + "'  ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {

                return true;

            }
            else
            {
                return false;
            }
        }

        internal static int Delete原料入库行(string bguid)
        {
            string sql;
            sql = "delete Bus_StockInVolume where bguid='" + bguid + "'";
            return pub.ExecuteSql(pub.ConnectionString, sql, "原料入库行删除");
        }
        /// <summary>
        ///   Bus_StockInMaterial辅料入库是否已经有了
        /// </summary>
        /// <param name="存货编号"></param>
        /// <param name="批次号"></param>
        /// <returns></returns>
        internal static bool IsExistBatch(string 存货编号, string 批次号)
        {
            string sql;
            sql = " select InventoryCode,Batch from Bus_StockInMaterial where InventoryCode='" + 存货编号 + "' and Batch='" + 批次号 + "'";

            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {

                return true;

            }
            else
            {
                return false;
            }
        }


        /// <summary>
        ///     Temp_辅料入库是否已经有了
        /// </summary>
        /// <param name="存货编号"></param>
        /// <param name="批次号"></param>
        /// <returns></returns>
        internal static bool IsExistTempBatch(string 存货编号, string 批次号)
        {
            string sql;

            sql = " select 存货编号,批次号 from Temp_辅料入库  where 存货编号='" + 存货编号 + "' and 批次号='" + 批次号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {

                return true;

            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 根据存货名称和规格型号得到存货编号,辅材
        /// </summary>
        /// <param name="存货名称"></param>
        /// <param name="规格型号"></param>
        /// <returns></returns>
        internal static string GetInventoryCode(string 存货名称, string 规格型号)
        {
            string sql;
            sql = "select T_GOOD_CODE from T_VIEW_CIM where T_GOOD_NAME='" + 存货名称 + "' and T_GOOD_MODEL='" + 规格型号 + "' and T_GOOD_TYPE = '锭类'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                return tb.Rows[0]["T_GOOD_CODE"].ToString();
            }
            else
            {
                return "";
            }
        }
        /// <summary>
        /// 存货编号是否存在
        /// </summary>
        /// <param name="存货编号"></param>
        /// <returns></returns>
        internal static bool IsExistInventory(string 存货编号)
        {
            string sql;
            sql = "select T_GOOD_CODE from T_VIEW_CIM where T_GOOD_CODE='" + 存货编号 + "' ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 获得辅料的现存量
        /// </summary>
        /// <param name="workShopCode"></param>
        /// <param name="warehouseCode"></param>
        /// <param name="storageLocation"></param>
        /// <param name="inventoryCode"></param>
        /// <param name="batch"></param>
        /// <returns></returns>
        internal static decimal GetMaterialCurrentStock(string workShopCode, string warehouseCode, string storageLocation, string inventoryCode, string batch)
        {
            string sql;
            sql = " SELECT [WorkShopCode]    ,[WarehouseCode]      ,[StorageLocation]     ,[InventoryCode]     ,[Batch]      ,[MainBalance]      ,[AssistBalance] FROM [View_MaterialCurrent] ";
            sql += " where WorkShopCode='" + workShopCode + "' and warehouseCode='" + warehouseCode + "' and storageLocation='" + storageLocation + "' and inventoryCode ='" + inventoryCode + "' and batch='" + batch + "'";


            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                return pub.Todecimal(tb.Rows[0]["MainBalance"].ToString());
            }
            else
            {
                return 0;
            }

        }
        /// <summary>
        /// 是否存在原料卷新的卷号
        /// </summary>
        /// <param name="新原料卷号"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        internal static bool IsExistVolumeNew(string 新原料卷号)
        {
            string sql;
            sql = "select VolumeCodeNew from Bus_StockInVolume where VolumeCodeNew='" + 新原料卷号 + "' and left (DocCode,4)='YLRK'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        internal static void ListInventoryClass(UIComboBox uiComboBox)
        {

            uiComboBox.Items.Add("热轧");
            uiComboBox.Items.Add("生产辅料");
            uiComboBox.SelectedIndex = 0;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="工厂编号1"></param>
        /// <param name="uiComboBox产线"></param>
        /// <exception cref="NotImplementedException"></exception>
        internal static void ListWorkLine(string 工厂编号, string 部门编号, string workType, string 搜索条件, UIComboBox uiComboBox产线)
        {
            string sql;
            sql = "SELECT [guid]     ,[WorkShopCode]     ,[DepartGuid]     ,[DepartCode]     ,[WorkLineCode]     ,[WorkLineName]     ,[AuditDate]     ,[AuditStatus]     ,[AuditId]     ,[Auditor]     ,[Remark]     ,[CreateID]     ,[Creator]     ,[CreateDate]     ,[ModifyID]     ,[Modifier]     ,[ModifyDate] FROM  [Dic_WorkLine] ";
            sql += " where WorkShopCode='" + 工厂编号 + "' and DepartCode='" + 部门编号 + "' ";
            if (搜索条件 != "")
            {
                sql += " and WorkLineName like '%" + 搜索条件 + "%'";
            }
            sql += " and workType='" + workType + "'";
            sql += "  order by WorkLineCode  ";

            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                uiComboBox产线.DataSource = tb;
                uiComboBox产线.DisplayMember = "WorkLineName";
                uiComboBox产线.ValueMember = "WorkLineCode";

                uiComboBox产线.Refresh();

            }
            else
            {

                uiComboBox产线.DataSource = null;
                uiComboBox产线.Refresh();
            }
        } /// <summary>
          ///    显示下拉包含全部
          /// </summary>
          /// <param name="工厂编号"></param>
          /// <param name="部门编号"></param>
          /// <param name="workType"></param>
          /// <param name="搜索条件"></param>
          /// <param name="uiComboBox产线">WorkLineName:全部，WorkLineCode：全部</param>
        internal static void ListWorkLineAll(string 工厂编号, string 部门编号, string workType, string 搜索条件, UIComboBox uiComboBox产线)
        {
            string sql;
            sql = "SELECT [guid]     ,[WorkShopCode]     ,[DepartGuid]     ,[DepartCode]     ,[WorkLineCode]     ,[WorkLineName]     ,[AuditDate]     ,[AuditStatus]     ,[AuditId]     ,[Auditor]     ,[Remark]     ,[CreateID]     ,[Creator]     ,[CreateDate]     ,[ModifyID]     ,[Modifier]     ,[ModifyDate] FROM [Dic_WorkLine] ";
            sql += " where WorkShopCode='" + 工厂编号 + "' and DepartCode='" + 部门编号 + "' ";
            if (搜索条件 != "")
            {
                sql += " and WorkLineName like '%" + 搜索条件 + "%'";
            }
            sql += " and workType='" + workType + "'";
            sql += "  order by WorkLineCode  ";

            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                DataRow dr = tb.NewRow();
                dr["WorkLineName"] = "全部";
                dr["WorkLineCode"] = "全部";
                tb.Rows.InsertAt(dr, 0);
                uiComboBox产线.DisplayMember = "WorkLineName";
                uiComboBox产线.ValueMember = "WorkLineCode";
                uiComboBox产线.DataSource = tb;
                uiComboBox产线.Refresh();

            }
            else
            {

                uiComboBox产线.DataSource = null;
                uiComboBox产线.Refresh();
            }
        }
        internal static void DoBusVolume(string doccode)
        {
            throw new NotImplementedException();
        }
        /// <summary>
        /// 显示工厂产线后续的去向
        /// </summary>
        /// <param name="工厂编号1"></param>
        /// <param name="workLineCode"></param>
        /// <param name="uiComboBox去向"></param>
        /// <exception cref="NotImplementedException"></exception>
        internal static void ListWorkType(string workShopCode, string workType, UIComboBox uiComboBox去向)
        {
            string sql;
           
            sql = "select NextWorkType from Dic_WorkType where WorkShopCode='" + workShopCode + "' and WorkType='" + workType + "' order by sort ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                uiComboBox去向.DataSource = tb;
                uiComboBox去向.DisplayMember = "NextWorkType";
                uiComboBox去向.ValueMember = "NextWorkType";
                uiComboBox去向.Refresh();
            }
            else
            {
                uiComboBox去向.DataSource = null;
                uiComboBox去向.Refresh();
            }
        }
        internal static void ListNextWorkTypeBytWorkType(string workShopCode, string workType, UIComboBox uiComboBox去向)
        {
            string sql;

            sql = "select NextWorkType from Dic_WorkType where WorkShopCode='" + workShopCode + "' and WorkType='" + workType + "' order by sort ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                uiComboBox去向.DataSource = tb;
                uiComboBox去向.DisplayMember = "NextWorkType";
                uiComboBox去向.ValueMember = "NextWorkType";
                uiComboBox去向.Refresh();
            }
            else
            {
                uiComboBox去向.DataSource = null;
                uiComboBox去向.Refresh();
            }
        }
        internal static void ListNextWorkTypeBytWorkTypeAll(string workShopCode, string workType, UIComboBox uiComboBox去向)
        {
            string sql;

            sql = "select NextWorkType from Dic_WorkType where WorkShopCode='" + workShopCode + "' and WorkType='" + workType + "' order by sort ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                DataRow dr = tb.NewRow();
                dr["NextWorkType"] = "全部";
                dr["NextWorkType"] = "全部";
                tb.Rows.InsertAt(dr, 0);
                uiComboBox去向.DataSource = tb;
                uiComboBox去向.DisplayMember = "NextWorkType";
                uiComboBox去向.ValueMember = "NextWorkType";
                uiComboBox去向.Refresh();
            }
            else
            {
                uiComboBox去向.DataSource = null;
                uiComboBox去向.Refresh();
            }
        }

        internal static void ListWorkTypeAll(string workShopCode, string workLineCode, UIComboBox uiComboBox去向)
        {
            string sql;
            string workType = GetWorkTypeByWorkLineCode(workShopCode, workLineCode);
            sql = "select NextWorkType from Dic_WorkType where WorkShopCode='" + workShopCode + "' and WorkType='" + workType + "' order by sort ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                DataRow dr = tb.NewRow();
                dr["NextWorkType"] = "全部";
                tb.Rows.InsertAt(dr, 0);
                uiComboBox去向.DataSource = tb;
                uiComboBox去向.DisplayMember = "NextWorkType";
                uiComboBox去向.ValueMember = "NextWorkType";
                uiComboBox去向.Refresh();
            }
            else
            {
                uiComboBox去向.DataSource = null;
                uiComboBox去向.Refresh();
            }
        }

        private static string GetWorkTypeByWorkLineCode(string workShopCode, string workLineCode)
        {
            string sql;
            sql = "select WorkType from Dic_WorkLine where WorkShopCode='" + workShopCode + "' and WorkLineCode='" + workLineCode + "' ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                return tb.Rows[0]["WorkType"].ToString();
            }
            else
            {
                return "";
            }
        }
        /// <summary>
        /// 规格是否符合格式
        /// </summary>
        /// <param name="规格"></param>
        /// <returns></returns>
        internal static bool IsRightSize(string 规格)
        {
            string 厚度;
            string 宽度;
            string 虚拟值;
           

            try
            {
                string[] gg = 规格.Split("*");
                厚度 = gg[0];
                宽度 = gg[1];
                虚拟值 = gg[2];
                if (pub.Todecimal(厚度) <= pub.Todecimal(0.15) || pub.Todecimal(厚度)>5)
                {
                    return false;
                }
                if (pub.Todecimal(宽度) <pub.Todecimal( 100) || pub.Todecimal(宽度)>1800)
                {
                    return false;
                }
                if (虚拟值 != "C")
                {
                    return false;
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
        /// <summary>
        /// 工厂的加工种类的下一个加工种类
        /// </summary>
        /// <param name="workShopCode">工厂编号</param>
        /// <param name="workType">当前工作种类</param>
        /// <param name="nextWorkType">下一个工作种类</param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        internal static bool IsRightNextWorkType(string workShopCode, string workType, string nextWorkType)
        {
            string sql;
            sql = "select * from Dic_WorkType where WorkShopCode='" + workShopCode + "' and workType='" + workType + "'  and NextWorkType='" + nextWorkType + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 检查是否被计划过了
        /// </summary>
        ///       <param name="workShopCode">工厂编号</param>
        /// <param name="formWorkType">工作种类</param>
        /// <param name="volumeCodeNew">新卷号</param>
        /// <returns></returns>
        internal static bool IsInPlan(string workShopCode, string formWorkType, string volumeCodeNew)
        {
            bool r = false;
            string sql;
            switch (formWorkType)
            {
                case "酸洗":
                    {
                        sql = "select * from Bus_PlanPickling where WorkShopCode='" + workShopCode + "' and VolumeCodeNew='" + volumeCodeNew + "'";
                        DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
                        if (tb.Rows.Count > 0)
                        {
                            r = true;
                        }
                        break;
                    }
                case "轧硬":
                    {
                        r = false;
                        break;
                    }
                case "镀锌":
                    {
                        r = false;
                        break;
                    }
                case "彩涂":
                    {
                        r = false;
                        break;
                    }
                case "罩退":
                    {
                        r = false;
                        break;
                    }
                case "退火":
                    {
                        r = false;
                        break;
                    }
                case "硅钢":
                    {
                        r = false;
                        break;
                    }
                default:
                    {
                        r = false;
                        break;
                    }
            }
            return r;
        }
        /// <summary>
        /// 返回卷号和库位号是否有这个卷未出库
        /// </summary>
        /// <param name="workShopCode"></param>
        /// <param name="volumeCodeNew"></param>
        /// <param name="storageLocation"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        internal static bool IsVolumeInStorageLocation(string workShopCode, string volumeCodeNew, string storageLocation)
        {
            string sql;
            sql = "SELECT   WorkShopCode, WarehouseCode, StorageLocation, VolumeCode, VolumeCodeNew ";
            sql += " FROM      View_VolumeLocationBalance where workShopCode='" + workShopCode + "' and  storageLocation='" + storageLocation + "' and volumeCodeNew='" + volumeCodeNew + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            return tb.Rows.Count > 0;
        }

        internal static string GetTime()
        {
            try
            {
                string sql;
                sql = "select getdate() ";
                DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
                return tb.Rows[0][0].ToString();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        internal static void ToExcel(DataTable dataTable)
        {
            string path;
            System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();
            saveFileDialog.Filter = "Excel文件 (*.XLSX)|*.XLSX";
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                path = saveFileDialog.FileName;
                if (!File.Exists(path))
                {
                    MiniExcel.SaveAs(path, dataTable, true, "sheet1", ExcelType.XLSX);
                    MessageBox.Show("文件保存成功!", "提示", MessageBoxButtons.OK);
                }
                else
                {
                    MessageBox.Show("文件已经存在,请重试!", "提示", MessageBoxButtons.OK);
                    return;
                }

            }
        }

        internal static string 去掉前缀(string 原卷号)
        {
            if (原卷号.ToUpper().IndexOf("PHR") >= 0|| 原卷号.ToUpper().IndexOf("PHS") >= 0|| 原卷号.ToUpper().IndexOf("PHY") >= 0|| 原卷号.ToUpper().IndexOf("PHD") >= 0|| 原卷号.ToUpper().IndexOf("PHZ") >= 0|| 原卷号.ToUpper().IndexOf("PHT") >= 0|| 原卷号.ToUpper().IndexOf("PHC") >= 0)
            {
                return 原卷号.Substring(3);
            }
            else
            {
                return 原卷号;

            }


        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="数字"></param>
        /// <param name="小数位数">0-5</param>
        /// <returns></returns>

        internal static string Todecimal(string 数字, int 小数位数)
        {
            if (小数位数 == 1)
            {
                return (Todecimal(数字.ToString())).ToString("0.0");
            }
            else if (小数位数 == 2)
            {
                return (Todecimal(数字.ToString())).ToString("0.00");
            }
            else if (小数位数 == 3)
            {
                return (Todecimal(数字.ToString())).ToString("0.000");
            }
            else if (小数位数 == 4)
            {
                return (Todecimal(数字.ToString())).ToString("0.0000");
            }
            else if (小数位数 == 5)
            {
                return (Todecimal(数字.ToString())).ToString("0.00000");

            }
            else if (小数位数 == 0)
            {
                return (Todecimal(数字.ToString())).ToString("0");
            }
            else
            {
                return (Todecimal(数字.ToString())).ToString();
            }
        }
        /// <summary>
        /// 班别
        /// </summary>
        /// <param name="v"></param>
        /// <exception cref="NotImplementedException"></exception>
        internal static void ListDayShift(string WorkShopCode, UIComboBox uiComboBox)
        {
            string sql;
            sql = "SELECT   guid, WorkShopGuid, WorkShopCode, DayShiftCode, DayShiftName, AuditDate, AuditStatus, AuditId, Auditor, Remark,  CreateID, Creator, CreateDate, ModifyID, Modifier, ModifyDate FROM      Dic_DayShift";
            sql += " where WorkShopCode='" + WorkShopCode + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                uiComboBox.DataSource = tb;
                uiComboBox.DisplayMember = "DayShiftName";
                uiComboBox.ValueMember = "DayShiftCode";
                uiComboBox.Refresh();
            }
            else
            {
                uiComboBox.DataSource = null;
                uiComboBox.Refresh();
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="工厂编号1"></param>
        /// <param name="workLineCode"></param>
        /// <param name="uiComboBoxWorkTeam"></param>
        internal static void ListWorkTeam(string 工厂编号, string workLineCode, UIComboBox uiComboBoxWorkTeam)
        {
            string sql;
            sql = @"    SELECT   dbo.Dic_WorkLine.WorkShopCode, dbo.Dic_WorkTeam.WorkTeamCode, dbo.Dic_WorkTeam.WorkTeamName, 
                dbo.Dic_TeamLine.WorkLineCode
FROM      dbo.Dic_WorkLine INNER JOIN
                dbo.Dic_TeamLine ON dbo.Dic_WorkLine.WorkLineCode = dbo.Dic_TeamLine.WorkLineCode INNER JOIN
                dbo.Dic_WorkTeam ON dbo.Dic_TeamLine.WorkTeamGuid = dbo.Dic_WorkTeam.guid where dbo.Dic_WorkLine.WorkShopCode='" + 工厂编号 + "' and  dbo.Dic_TeamLine.WorkLineCode='" + workLineCode + "'";
            sql += " order by dbo.Dic_WorkTeam.WorkTeamCode ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                uiComboBoxWorkTeam.DataSource = tb;
                uiComboBoxWorkTeam.DisplayMember = "WorkTeamName";
                uiComboBoxWorkTeam.ValueMember = "WorkTeamCode";
                uiComboBoxWorkTeam.Refresh();
            }
            else
            {
                uiComboBoxWorkTeam.DataSource = null;
                uiComboBoxWorkTeam.Refresh();
            }
        }
        /// <summary>
        /// 根据酸洗原料卷号找到报工过了的guid，如果没有，就塞入一个计划到执行中，并一个返回guid
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        internal static string Get酸洗报工guid(string 投入卷号,out string 用来保存的原卷号 )
        {
            string sql;
            string 查询投入卷号 = "PHR"+投入卷号.Replace("PHR", "");  //只查卷号的7位纯数字
            sql = "select guid,OriginalVolumeNew from Bus_PicklingOriginal where OriginalVolumeNew ='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                用来保存的原卷号 = tb.Rows[0]["OriginalVolumeNew"].ToString();
                return tb.Rows[0]["guid"].ToString();
            }
            else
            {
                //产生一次
                string guid = Guid.NewGuid().ToString();

                sql = "insert into Bus_PicklingOriginal( guid, WorkShopGuid, WorkShopCode, OriginalVolume, OriginalVolumeNew, OriginalSize,   ";
                sql += " OriginalMaterial, OriginalWeight, PlanSize, OriginalAddress,  CreateID, Creator, CreateDate, IsClosed) ";
                sql += " select '" + guid + "',WorkShopGuid ,WorkShopCode,VolumeCode,VolumeCodeNew,Originalsize,Material,Weight,OutputSize,Address,";
                sql += " '" + pub.sys_user.User_Id + "','" + pub.sys_user.UserTrueName + "',getdate(),'N' from Bus_PlanPickling where VolumeCodeNew='" + 查询投入卷号 + "'";
                if (pub.ExecuteSql(pub.ConnectionString, sql, "酸洗报工投入卷信息塞入Bus_PicklingOriginal") > 0)
                {
                    用来保存的原卷号 = 查询投入卷号;
                    return guid;
                }
                else
                {
                    用来保存的原卷号 = "";
                    return "";
                }

            }
        }

        internal static void ListWorkLine(string 工厂编号, string workType, UIComboBox uiComboBox产线)
        {
            string sql;
            sql = "SELECT [guid]     ,[WorkShopCode]     ,[DepartGuid]     ,[DepartCode]     ,[WorkLineCode]     ,[WorkLineName]     ,[AuditDate]     ,[AuditStatus]     ,[AuditId]     ,[Auditor]     ,[Remark]     ,[CreateID]     ,[Creator]     ,[CreateDate]     ,[ModifyID]     ,[Modifier]     ,[ModifyDate] FROM  [Dic_WorkLine] ";
            sql += " where WorkShopCode='" + 工厂编号 + "'    ";
               if (workType!="退火")
            {
                sql += " and workType='" + workType + "'";
            }
            else
            {
                sql += " and WorkLineName='二期镀退一线'";
            }
           


            sql += "  order by WorkLineCode  ";

            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null && tb.Rows.Count > 0)
            {
                uiComboBox产线.DataSource = tb;
                uiComboBox产线.DisplayMember = "WorkLineName";
                uiComboBox产线.ValueMember = "WorkLineCode";

                uiComboBox产线.Refresh();

            }
            else
            {

                uiComboBox产线.DataSource = null;
                uiComboBox产线.Refresh();
            }
        }
        internal static void ListWorkLineAll(string 工厂编号, string workType, UIComboBox uiComboBox产线)
        {
            string sql;
            sql = "SELECT [guid]     ,[WorkShopCode]     ,[DepartGuid]     ,[DepartCode]     ,[WorkLineCode]     ,[WorkLineName]     ,[AuditDate]     ,[AuditStatus]     ,[AuditId]     ,[Auditor]     ,[Remark]     ,[CreateID]     ,[Creator]     ,[CreateDate]     ,[ModifyID]     ,[Modifier]     ,[ModifyDate] FROM  [Dic_WorkLine] ";
            sql += " where WorkShopCode='" + 工厂编号 + "'    ";

            sql += " and workType='" + workType + "'";
            sql += "  order by WorkLineCode  ";

            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null && tb.Rows.Count > 0)
            {
                DataRow dr = tb.NewRow();
                dr["WorkLineName"] = "全部";
                dr["WorkLineCode"] = "全部";
                tb.Rows.InsertAt(dr,0);
                uiComboBox产线.DataSource = tb;
                uiComboBox产线.DisplayMember = "WorkLineName";
                uiComboBox产线.ValueMember = "WorkLineCode";

                uiComboBox产线.Refresh();

            }
            else
            {

                uiComboBox产线.DataSource = null;
                uiComboBox产线.Refresh();
            }
        }

        internal static Dic_WorkLine GetWorkLineByLineCode(string workShopCode, string workLineCode)
        {
            string sql;
            sql = @"SELECT   guid, WorkShopCode, DepartGuid, DepartCode, WorkType, WorkLineCode, WorkLineName, AuditDate, AuditStatus, 
                AuditId, Auditor, Remark, CreateID, Creator, CreateDate, ModifyID, Modifier, ModifyDate, V1, V2
FROM      Dic_WorkLine   where WorkShopCode='" + workShopCode + "' and  WorkLineCode='" + workLineCode + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Dic_WorkLine> dic_worklines = pub.GetTableToList<Dic_WorkLine>(tb);
                return dic_worklines[0];
            }
            else
            {
                Dic_WorkLine dic_workline = new Dic_WorkLine();
                return dic_workline;
            }
        }

        internal static void ListRank(string 工厂编号, UIComboBox uiComboBox质量等级)
        {
            string sql;
            sql = "SELECT   guid, WorkShopGuid, WorkShopCode, RankName, AuditDate, AuditStatus, AuditId, Auditor, Remark, CreateID, Creator, CreateDate, ModifyID, Modifier, ModifyDate FROM      Dic_Rank ";
            sql += " where WorkShopCode='" + 工厂编号 + "'    ";
            sql += "  order by RankName  ";

            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                DataRow dr = tb.NewRow();
                dr["RankName"] = "全部";
                dr["RankName"] = "全部";
                tb.Rows.InsertAt(dr, 0);
                uiComboBox质量等级.DataSource = tb;
                uiComboBox质量等级.DisplayMember = "RankName";
                uiComboBox质量等级.ValueMember = "RankName";

                uiComboBox质量等级.Refresh();

            }
            else
            {

                uiComboBox质量等级.DataSource = null;
                uiComboBox质量等级.Refresh();
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="OriginalVolumeNew"></param>
        /// <returns>true 表示关闭，false 表示未关闭，找不到表示没做过</returns>

        internal static bool Is酸洗报工原始卷被关闭(string 投入卷号)
        {
            string sql;
            sql = "select IsClosed from Bus_PicklingOriginal where  OriginalVolumeNew='" + 投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                if (tb.Rows[0]["IsClosed"].ToString() == "Y")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="酸洗产出卷号"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        internal static string Get酸洗产出卷的后续状态(string 酸洗产出卷号)
        {
            ///1,根据卷号找到去向
            string 状态 = "未使用";
            string sql = @"SELECT    OutputNext FROM      Bus_PicklingOutput where OutputVolumeNew='" + 酸洗产出卷号 + "'  ";
            DataTable tb1 = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb1.Rows.Count > 0)
            {
                string 去向 = tb1.Rows[0]["OutputNext"].ToString();
                if (去向 == "轧硬")
                {
                    sql = "select * from Bus_HardOutput where VolumeCodeNew ='" + 酸洗产出卷号 + "'";
                    DataTable tb2 = pub.GetDataTable(pub.ConnectionString, sql);
                    if (tb2.Rows.Count > 0)
                    {
                        sql = " update Bus_PicklingOutput set OutputEndStatus='被轧硬使用'   where OutputVolumeNew ='" + 酸洗产出卷号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "更新酸洗卷的后续状态");
                        状态 = "被轧硬使用";
                    }
                }
                else if (去向 == "镀锌")
                {
                    sql = "select * from Bus_ZincOriginal where OriginalVolumeNew ='" + 酸洗产出卷号 + "'";
                    DataTable tb3 = pub.GetDataTable(pub.ConnectionString, sql);
                    if (tb3.Rows.Count > 0)
                    {
                        sql = " update Bus_PicklingOutput set OutputEndStatus='被镀锌使用'   where OriginalVolumeNew ='" + 酸洗产出卷号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "更新酸洗卷的后续状态");
                        状态 = "被镀锌使用";
                    }
                }
                else   //入库
                {
                    sql = "select * from Bus_ProductInStock where VolumeCodeNew ='" + 酸洗产出卷号 + "'";
                    DataTable tb4 = pub.GetDataTable(pub.ConnectionString, sql);
                    if (tb4.Rows.Count > 0)
                    {
                        sql = " update Bus_PicklingOutput set OutputEndStatus='已入库'   where OriginalVolumeNew ='" + 酸洗产出卷号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "更新酸洗卷的后续状态");
                        状态 = "已入库";
                    }
                }

            }
            else
            {
                状态 = "产出卷被删了";
            }
            return 状态;

        }

        internal static Bus_StockOutVolume Get酸洗出库卷信息(string 投入卷号)
        {
            string sql;
            string 查询投入卷号 = "PHR" + 投入卷号.Replace("PHR", "");//纯数字查询
            sql = "SELECT   guid, Bguid, DocCode, RowNumber, WorkShopCode, WarehouseCode, StorageLocation, VolumeCode, VolumeCodeNew,  ";
            sql += "    InventoryCode, InventoryName, Size, Thick, Width, Material, Address, Weight, CID, Virtual, OutputSize, ProductSize, ";
            sql += " NextWorkType, Remark FROM   Bus_StockOutVolume where VolumeCodeNew='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_StockOutVolume> bus_stockoutvolumes = pub.GetTableToList<Bus_StockOutVolume>(tb);
                return bus_stockoutvolumes[0];
            }
            else
            {
                return null;
            }
        }

        internal static List<Bus_PicklingOutput> Get酸洗产出卷信息All(string 投入卷号)
        {
            string sql;
            
            string 查询投入卷号 = "PHR" + 投入卷号.Replace("PHR", "");//纯数字查询
            sql = @"SELECT   OutputGuid, guid, VolumeCodeNew,Row, OutputVolumeNew, OutputSize, OutputThick, OutputWidth, OutputMaterial, OutputWeight,OutputMeter,  
                OutputQualityGrade, OutputQualityInformation, OutputEndStatus, OutputNext, PrintTimes, DepartCode, DepartName, 
                WorkLineCode, WorkLineName, WorkTeamCode, WorkTeamName, DayShiftCode, DayShiftName, CreateID, Creator, 
                CreateDate, ModifyID, Modifier, ModifyDate
                FROM      Bus_PicklingOutput where VolumeCodeNew='" + 查询投入卷号 + "' ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_PicklingOutput> bus_picklingoutputs = pub.GetTableToList<Bus_PicklingOutput>(tb);
                return bus_picklingoutputs;
            }
            else
            {
                return null;
            }


        }
        internal static Bus_PicklingOutput Get酸洗产出卷信息(string 产出卷号)
        {
            string sql;
            sql = @"SELECT   OutputGuid, guid, VolumeCodeNew,Row, OutputVolumeNew, OutputSize, OutputThick, OutputWidth, OutputMaterial, OutputWeight, OutputMeter,
                OutputQualityGrade, OutputQualityInformation, OutputEndStatus, OutputNext, PrintTimes, DepartCode, DepartName, 
                WorkLineCode, WorkLineName, WorkTeamCode, WorkTeamName, DayShiftCode, DayShiftName, CreateID, Creator, 
                CreateDate, ModifyID, Modifier, ModifyDate  ,Customer 
FROM      Bus_PicklingOutput where OutputVolumeNew='" + 产出卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_PicklingOutput> bus_picklingoutputs = pub.GetTableToList<Bus_PicklingOutput>(tb);
                return bus_picklingoutputs[0];
            }
            else
            {
                return null;
            }


        }

        internal static void ListMaterialBatch(string 辅材料号, UIComboBox uiComboBox辅材批号)
        {
            string sql;
            sql = @" SELECT   guid, Bguid, DocCode, RowNumber, WorkShopCode, WarehouseCode, StorageLocation, T_CONTRACT_CODE, 
                T_ORDER, T_GOOD_UNIT, T_GOOD_NUM, T_GOOD_PRICE, T_GOOD_MONEY, InventoryCode, Size, CID, Batch, 
                QuantityMain, QuantityAssist
FROM      Bus_StockInMaterial 
 t where InventoryCode='" + 辅材料号 + "' order by Batch ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                uiComboBox辅材批号.DataSource = tb;
                uiComboBox辅材批号.DisplayMember = "Batch";
                uiComboBox辅材批号.ValueMember = "Batch";
                uiComboBox辅材批号.Refresh();
            }
            else
            {
                uiComboBox辅材批号.DataSource = null;
                uiComboBox辅材批号.Refresh();
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="uiComboBox钢号"></param>
        internal static void List产品钢号(string 工厂编号, string 加工类别, UIComboBox uiComboBox钢号)
        {
            string sql;
            if (加工类别=="冷轧")
            {
                加工类别 = "罩退";
            }
            sql = "SELECT    WorkShopCode, WorkType, ProductMaterial FROM      Dic_WorkTypeMaterial ";
            sql += "  where WorkShopCode='" + 工厂编号 + "' and WorkType='" + 加工类别 + "'";

            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                uiComboBox钢号.DataSource = tb;
                uiComboBox钢号.DisplayMember = "ProductMaterial";
                uiComboBox钢号.ValueMember = "ProductMaterial";
                uiComboBox钢号.Refresh();
            }
            else
            {
                uiComboBox钢号.DataSource = null;
                uiComboBox钢号.Refresh();
            }
        }

        internal static void ListWorkType(string 工厂编号, UIComboBox uiComboBox加工类别)
        {
            string sql;
            sql = @"  SELECT    distinct WorkType FROM      Dic_WorkType where WorkShopCode='" + 工厂编号 + "' order by WorkType  ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                uiComboBox加工类别.DataSource = tb;
                uiComboBox加工类别.DisplayMember = "WorkType";
                uiComboBox加工类别.ValueMember = "WorkType";
                uiComboBox加工类别.Refresh();
            }
            else
            {
                uiComboBox加工类别.DataSource = null;
                uiComboBox加工类别.Refresh();
            }
        }

        internal static List<Bus_PlanPickling> Get酸洗计划组(string volumeCodeNew)
        {
            string sql = @"SELECT   guid, WorkShopGuid, WorkShopCode, DepartGuid, DepartCode, WorkLineCode, WorkLineName, WorkDate, RowNumber, 
                OriginalSize, Address, VolumeCode, VolumeCodeNew, Weight, OutputSize, ProductSize, NextWorkType, Remark, 
                Material, StorageLocation, MAC, CreateID, Creator, CreateDate, ApproverID, Approver, ApproverDate, IsSendToNC, 
                SendToNCDate, Customer ";
            sql += "   FROM      Bus_PlanPickling where VolumeCodeNew='" + volumeCodeNew + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null && tb.Rows.Count > 0)
            {
                List<Bus_PlanPickling> bus_planpicklings = pub.GetTableToList<Bus_PlanPickling>(tb);
                return bus_planpicklings;
            }
            else
            {

                return null;
            }
        }

        internal static List<Bus_PlanPickling> GetBus_PlanPicklingsByVolumeCode(string volumeCodeNew, string NextWorkType)
        {
            string sql = @"SELECT   guid, WorkShopGuid, WorkShopCode, DepartGuid, DepartCode, WorkLineCode, WorkLineName, WorkDate, RowNumber, OriginalSize, Address, VolumeCode, VolumeCodeNew,";
            sql += " Weight, OutputSize, ProductSize, NextWorkType, Remark, Material, StorageLocation, MAC, CreateID, Creator, CreateDate, ApproverID, Approver, ApproverDate, IsSendToNC, SendToNCDate ";
            sql += "   FROM      Bus_PlanPickling where VolumeCodeNew='" + volumeCodeNew + "' and NextWorkType ='" + NextWorkType + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null && tb.Rows.Count > 0)
            {
                List<Bus_PlanPickling> bus_planpicklings = pub.GetTableToList<Bus_PlanPickling>(tb);
                return bus_planpicklings;
            }
            else
            {

                return null;
            }
        }

        internal static List<Bus_PlanHard> GetBus_PlanHardsByVolumeCode(string volumeCodeNew, string NextWorkType)
        {
            string sql = @"SELECT   guid, WorkShopGuid, WorkShopCode, DepartGuid, DepartCode, WorkLineCode, WorkLineName, WorkDate, RowNumber, OriginalSize, Address, VolumeCode, VolumeCodeNew,";
            sql += " Weight, OutputSize, ProductSize, NextWorkType, Remark, Material, StorageLocation, MAC, CreateID, Creator, CreateDate, ApproverID, Approver, ApproverDate, IsSendToNC, SendToNCDate,Customer ";
            sql += "   FROM      Bus_PlanHard where VolumeCodeNew='" + volumeCodeNew + "' and NextWorkType ='" + NextWorkType + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null && tb.Rows.Count > 0)
            {
                List<Bus_PlanHard> bus_planhards = pub.GetTableToList<Bus_PlanHard>(tb);
                return bus_planhards;
            }
            else
            {

                return null;
            }
        }
        internal static Bus_PlanHard Get轧硬计划(string volumeCodeNew)
        {
            volumeCodeNew = "PHS"+volumeCodeNew.Replace("PHS","");
            string sql = @"SELECT   guid, WorkShopGuid, WorkShopCode, DepartGuid, DepartCode, WorkLineCode, WorkLineName, WorkDate, RowNumber, OriginalSize, Address, VolumeCode, VolumeCodeNew,";
            sql += " Weight, OutputSize, ProductSize, NextWorkType, Remark, Material, StorageLocation, MAC, CreateID, Creator, CreateDate, ApproverID, Approver, ApproverDate, IsSendToNC, SendToNCDate,Customer ";
            sql += "   FROM      Bus_PlanHard where VolumeCodeNew='" + volumeCodeNew + "'  ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null && tb.Rows.Count > 0)
            {
                List<Bus_PlanHard> bus_planhards = pub.GetTableToList<Bus_PlanHard>(tb);
                return bus_planhards[0];
            }
            else
            {

                return null;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="投入卷号"></param>
        /// <returns></returns>
        internal static string Get轧硬报工guid(string 投入卷号)
        {
            string sql;
            string 查询投入卷号 = "PHS" + 投入卷号.Replace("PHS", "");  //只查卷号的7位纯数字
            sql = "select guid from Bus_HardOriginal where OriginalVolumeNew ='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                return tb.Rows[0]["guid"].ToString();
            }
            else
            {
                //产生一次
                string guid = Guid.NewGuid().ToString();
                sql = "insert into Bus_HardOriginal( guid, WorkShopGuid, WorkShopCode, OriginalVolume, OriginalVolumeNew, OriginalSize,ProductSize,   ";
                sql += " OriginalMaterial, OriginalWeight,OriginalMeter,    CreateID, Creator, CreateDate, IsClosed,Customer) ";
                sql += " select '" + guid + "',WorkShopGuid ,工厂编号,'',卷号,酸洗产出规格,成品规格,材质,重量,米数,";
                sql += " '" + pub.sys_user.User_Id + "','" + pub.sys_user.UserTrueName + "',getdate(),'N',客户 from View_已酸洗未轧硬 where 卷号='" + 查询投入卷号 + "'";
                if (pub.ExecuteSql(pub.ConnectionString, sql, "轧硬报工投入卷信息塞入Bus_HardOriginal") > 0)
                {
                    return guid;
                }
                else
                {
                    return "";
                }

            }
        }

        internal static bool Is轧硬报工原始卷被关闭(string 投入卷号)
        {
            string sql;
            string 查询投入卷号 = "PHS" + 投入卷号.Replace("PHS", "");
            sql = "select IsClosed from Bus_HardOriginal where  OriginalVolumeNew='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                if (tb.Rows[0]["IsClosed"].ToString() == "Y")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        internal static List<Bus_HardOutput> Get轧硬产出卷信息All(string 投入卷号)
        {
            string sql;
            string 查询投入卷号 = "PHS" + 投入卷号.Replace("PHS", "");
            sql = @"SELECT   OutputGuid, guid, VolumeCodeNew,Row, OutputVolumeNew, OutputSize, OutputThick, OutputWidth, OutputMaterial, OutputWeight,OutputMeter, 
                OutputQualityGrade, OutputQualityInformation, OutputEndStatus, OutputNext, PrintTimes, DepartCode, DepartName, 
                WorkLineCode, WorkLineName, WorkTeamCode, WorkTeamName, DayShiftCode, DayShiftName, CreateID, Creator, 
                CreateDate, ModifyID, Modifier, ModifyDate
              FROM      Bus_HardOutput where VolumeCodeNew='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_HardOutput> bus_hardoutputs = pub.GetTableToList<Bus_HardOutput>(tb);
                return bus_hardoutputs;
            }
            else
            {
                return null;
            }
        }

        internal static Bus_HardOutput Get轧硬产出卷信息(string 产出卷号)
        {
            string sql;
            sql = @"SELECT   OutputGuid, guid, VolumeCodeNew,Row, OutputVolumeNew, OutputSize, OutputThick, OutputWidth, OutputMaterial, OutputWeight,OutputMeter, 
                OutputQualityGrade, OutputQualityInformation, OutputEndStatus, OutputNext, PrintTimes, DepartCode, DepartName, 
                WorkLineCode, WorkLineName, WorkTeamCode, WorkTeamName, DayShiftCode, DayShiftName, CreateID, Creator, 
                CreateDate, ModifyID, Modifier, ModifyDate ,Customer 
FROM      Bus_HardOutput where OutputVolumeNew = '" + 产出卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_HardOutput> bus_hardoutputs = pub.GetTableToList<Bus_HardOutput>(tb);
                return bus_hardoutputs[0];
            }
            else
            {
                return null;
            }
        }

        internal static string Get轧硬产出卷的后续状态(string 轧硬产出卷号)
        {
            ///1,根据卷号找到去向
            string 状态 = "未使用";
            string sql = @"SELECT    OutputNext FROM      Bus_HardOutput where OutputVolumeNew='" + 轧硬产出卷号 + "'  ";
            DataTable tb1 = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb1.Rows.Count > 0)
            {
                string 去向 = tb1.Rows[0]["OutputNext"].ToString();
                if (去向 == "镀锌")
                {
                    sql = "select * from Bus_ZincOutput where VolumeCodeNew ='" + 轧硬产出卷号 + "'";
                    DataTable tb2 = pub.GetDataTable(pub.ConnectionString, sql);
                    if (tb2.Rows.Count > 0)
                    {
                        sql = " update Bus_HardOutput set OutputEndStatus='被镀锌使用'   where OutputVolumeNew ='" + 轧硬产出卷号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "更新轧硬卷的后续状态");
                        状态 = "被镀锌使用";
                    }
                }
                else if (去向 == "罩退")
                {
                    sql = "select * from Bus_CoverFireOutput where VolumeCodeNew ='" + 轧硬产出卷号 + "'";
                    DataTable tb3 = pub.GetDataTable(pub.ConnectionString, sql);
                    if (tb3.Rows.Count > 0)
                    {
                        sql = " update Bus_HardOutput set OutputEndStatus='被罩退使用'   where OriginalVolumeNew ='" + 轧硬产出卷号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "更新轧硬卷的后续状态");
                        状态 = "被罩退使用";
                    }
                }
                else if (去向 == "退火")
                {
                    sql = "select * from Bus_FireOutput where VolumeCodeNew ='" + 轧硬产出卷号 + "'";
                    DataTable tb4 = pub.GetDataTable(pub.ConnectionString, sql);
                    if (tb4.Rows.Count > 0)
                    {
                        sql = " update Bus_HardOutput set OutputEndStatus='被退火使用'   where OriginalVolumeNew ='" + 轧硬产出卷号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "更新轧硬卷的后续状态");
                        状态 = "被退火使用";
                    }
                }
                else if (去向 == "硅钢")
                {
                    sql = "select * from Bus_SiOutput where VolumeCodeNew ='" + 轧硬产出卷号 + "'";
                    DataTable tb5 = pub.GetDataTable(pub.ConnectionString, sql);
                    if (tb5.Rows.Count > 0)
                    {
                        sql = " update Bus_HardOutput set OutputEndStatus='被硅钢使用'   where OriginalVolumeNew ='" + 轧硬产出卷号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "更新轧硬卷的后续状态");
                        状态 = "被硅钢使用";
                    }
                }
                else   //入库
                {
                    sql = "select * from Bus_ProductInStock where VolumeCodeNew ='" + 轧硬产出卷号 + "'";
                    DataTable tb6 = pub.GetDataTable(pub.ConnectionString, sql);
                    if (tb6.Rows.Count > 0)
                    {
                        sql = " update Bus_HardOutput set OutputEndStatus='已入库'   where OriginalVolumeNew ='" + 轧硬产出卷号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "更新轧硬卷的后续状态");
                        状态 = "已入库";
                    }
                }

            }
            else
            {
                状态 = "产出卷被删了";
            }
            return 状态;
        }

        internal static Bus_HardOriginal Get轧硬投入信息(string WorkShopCode, string 投入卷号)
        {
            string sql;
            string 查询投入卷号 = "PHS" + 投入卷号.Replace("PHS", "");
           sql = @"SELECT    guid, WorkShopGuid, WorkShopCode, OriginalVolume, OriginalVolumeNew, OriginalSize, OriginalWeight,OriginalMeter, 
                   OriginalMaterial, PlanSize, CreateID, Creator, CreateDate, ModifyID, Modifier, ModifyDate, IsClosed, ColseUserId, 
                   ColseUserName, CloseDate , Customer FROM      [Bus_HardOriginal] where WorkShopCode='" + WorkShopCode + "' and OriginalVolumeNew='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count >0)
            {
                List<Bus_HardOriginal> bus_hardoriginals = pub.GetTableToList<Bus_HardOriginal>(tb);
                return bus_hardoriginals[0];
            }
            else
            {

                return null;
            }
        }

        internal static string Get镀锌报工guid(string 投入卷号)
        {
            string sql;

            string 查询投入卷号1 = "PHS" + 投入卷号.Replace("PHS", "");
            string 查询投入卷号2 = "PHY" + 投入卷号.Replace("PHY", "");
            sql = " select top 1  guid from Bus_ZincOriginal where (OriginalVolumeNew ='" + 查询投入卷号1 + "' or OriginalVolumeNew ='" + 查询投入卷号2 + "')";
            sql += " order by CreateDate desc  ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                return tb.Rows[0]["guid"].ToString();
            }
            else
            {
                //产生一次
                string guid = Guid.NewGuid().ToString();
                sql = "insert into Bus_ZincOriginal( guid, WorkShopGuid, WorkShopCode, OriginalVolume, OriginalVolumeNew, OriginalSize,   ";
                sql += " OriginalMaterial, OriginalWeight,OriginalMeter,  PlanSize,OriginalAddress,  CreateID, Creator, CreateDate, IsClosed ) ";
                sql += " select top 1 '" + guid + "',WorkShopGuid ,工厂编号,'',卷号,规格型号,材质,重量,米数,计划产出规格,产地,";
                sql += " '" + pub.sys_user.User_Id + "','" + pub.sys_user.UserTrueName + "',getdate(),'N'   from View_已酸洗轧硬未镀锌 ";
                sql +=" where  (卷号 ='" + 查询投入卷号1 + "' or 卷号 ='" + 查询投入卷号2 + "') order by 时间 desc  ";
                if (pub.ExecuteSql(pub.ConnectionString, sql, "轧硬报工投入卷信息塞入Bus_HardOriginal") > 0)
                {
                    //二次加工给 Bus_ZincOriginal 填上客户，和锌层厚度
                    //先看轧硬卷号的客户，如果有，就结束
                    //string 客户;
                    //客户 = pub.Get客户(投入卷号, "镀锌");
                    //string 锌层厚度;
                    //锌层厚度= pub.Get锌层厚度(投入卷号, "镀锌");

                    return guid;
                }
                else
                {
                    return "";
                }

            }
        }
          /// <summary>
          /// 根据镀锌的投入卷号获得需要的锌层厚度
          /// </summary>
          /// <param name="投入卷号"></param>
          /// <param name="加工类型"></param>
          /// <returns></returns>
        private static string Get锌层厚度(string 投入卷号, string 加工类型)
        {
            string sql;
            ///查计划
            ///
            string 查询投入卷号1 = "PHS" + 投入卷号.Replace("PHS", "");
            string 查询投入卷号2 = "PHY" + 投入卷号.Replace("PHY", "");
            sql = "select ZincThick Bus_PlanZinc where (VolumeCodeNew='" + 查询投入卷号1 + "' or VolumeCodeNew='" + 查询投入卷号2 + "') ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count ==0)
            {
                //镀锌计划没有
                return "";
            }
            else
            {
                return tb.Rows[0]["ZincThick"].ToString();
            }
        
        }

        private static string Get客户(string 投入卷号, string v)
        {
            throw new NotImplementedException();
        }

        internal static bool Is镀锌报工原始卷被关闭(string 投入卷号)
        {
            string sql;
            string 查询投入卷号1 = "PHS" + 投入卷号.Replace("PHS", "");  //酸洗
            string 查询投入卷号2 = "PHY" + 投入卷号.Replace("PHY", "");  //轧硬
            sql = "select IsClosed from Bus_ZincOriginal where  (OriginalVolumeNew='" + 查询投入卷号1 + "' or OriginalVolumeNew='" + 查询投入卷号2 + "' )";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                if (tb.Rows[0]["IsClosed"].ToString() == "Y")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        internal static bool Is镀铝锌报工原始卷被关闭(string 投入卷号)
        {
            string sql;
            string 查询投入卷号1 = "PHS" + 投入卷号.Replace("PHS", "");  //酸洗
            string 查询投入卷号2 = "PHY" + 投入卷号.Replace("PHY", "");  //轧硬
            sql = "select IsClosed from Bus_LvZincOriginal where  (OriginalVolumeNew='" + 查询投入卷号1 + "' or OriginalVolumeNew='" + 查询投入卷号2 + "' )";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                if (tb.Rows[0]["IsClosed"].ToString() == "Y")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        internal static List<Bus_ZincOutput> Get镀锌产出卷信息All(string 投入卷号)
        {
            string sql;
            string 查询投入卷号1 = "PHS" + 投入卷号.Replace("PHS", "");  //酸洗
            string 查询投入卷号2 = "PHY" + 投入卷号.Replace("PHY", "");  //轧硬
            sql = @"SELECT   OutputGuid, guid, VolumeCodeNew,Row, OutputVolumeNew, OutputSize, OutputThick, OutputWidth, OutputMaterial, OutputWeight, OutputMeter,
                OutputQualityGrade, OutputQualityInformation, OutputEndStatus, OutputNext, PrintTimes, DepartCode, DepartName, 
                WorkLineCode, WorkLineName, WorkTeamCode, WorkTeamName, DayShiftCode, DayShiftName, CreateID, Creator, 
                CreateDate, ModifyID, Modifier, ModifyDate
                FROM      Bus_ZincOutput where (VolumeCodeNew='" + 查询投入卷号1 + "' or VolumeCodeNew='" + 查询投入卷号2 + "')";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                 

                List<Bus_ZincOutput> bus_zincoutputs = pub.GetTableToList<Bus_ZincOutput>(tb);
                return bus_zincoutputs;
            }
            else
            {
                return null;
            }
        }

        internal static List<Bus_LvZincOutput> Get镀铝锌产出卷信息All(string 投入卷号)
        {
            string sql;
            string 查询投入卷号1 = "PHS" + 投入卷号.Replace("PHS", "");  //酸洗
            string 查询投入卷号2 = "PHY" + 投入卷号.Replace("PHY", "");  //轧硬
            sql = @"SELECT   OutputGuid, guid, VolumeCodeNew,Row, OutputVolumeNew, OutputSize, OutputThick, OutputWidth, OutputMaterial, OutputWeight, OutputMeter,
                OutputQualityGrade, OutputQualityInformation, OutputEndStatus, OutputNext, PrintTimes, DepartCode, DepartName, 
                WorkLineCode, WorkLineName, WorkTeamCode, WorkTeamName, DayShiftCode, DayShiftName, CreateID, Creator, 
                CreateDate, ModifyID, Modifier, ModifyDate
                FROM      Bus_LvZincOutput where (VolumeCodeNew='" + 查询投入卷号1 + "' or VolumeCodeNew='" + 查询投入卷号2 + "')";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {


                List<Bus_LvZincOutput> bus_zincoutputs = pub.GetTableToList<Bus_LvZincOutput>(tb);
                return bus_zincoutputs;
            }
            else
            {
                return null;
            }
        }


        internal static string Get镀锌产出卷的后续状态(string 镀锌产出卷号)
        {
            ///1,根据卷号找到去向
            string 状态 = "未使用";     //只看彩涂
            string sql = @"SELECT    OutputNext FROM      Bus_ZincOutput where OutputVolumeNew='" + 镀锌产出卷号 + "'  ";
            DataTable tb1 = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb1.Rows.Count > 0)
            {
                string 去向 = tb1.Rows[0]["OutputNext"].ToString();
                if (去向 == "彩涂")
                {
                    sql = "select * from Bus_PaintOutput   where  VolumeCodeNew ='" + 镀锌产出卷号 + "' ";
                    DataTable tb2 = pub.GetDataTable(pub.ConnectionString, sql);
                    if (tb2.Rows.Count > 0)
                    {
                        sql = " update Bus_ZincOutput set OutputEndStatus='被彩涂使用'   where OriginalVolumeNew ='" + 镀锌产出卷号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "更新镀锌卷的后续状态");
                        状态 = "被彩涂使用";
                    }
                }
               
                else   //入库
                {
                    sql = "select * from Bus_LablePrint where 生产批号 = '" + 镀锌产出卷号 + "' and 是否已打印 = '是'";
                    DataTable tb4 = pub.GetDataTable(pub.ConnectionString, sql);
                    if (tb4.Rows.Count > 0)
                    {
                        sql = " update Bus_PicklingOutput set OutputEndStatus='已入库'   where OriginalVolumeNew ='" + 镀锌产出卷号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "更新镀锌卷的后续状态");
                        状态 = "已入库";
                    }
                }

            }
            else
            {
                状态 = "产出卷被删了";
            }
            return 状态;
        }

        internal static string Get镀铝锌产出卷的后续状态(string 镀锌产出卷号)
        {
            ///1,根据卷号找到去向
            string 状态 = "未使用";     //只看彩涂
            string sql = @"SELECT    OutputNext FROM      Bus_LvZincOutput where OutputVolumeNew='" + 镀锌产出卷号 + "'  ";
            DataTable tb1 = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb1.Rows.Count > 0)
            {
                string 去向 = tb1.Rows[0]["OutputNext"].ToString();
                if (去向 == "彩涂")
                {
                    sql = "select * from Bus_PaintOutput   where  VolumeCodeNew ='" + 镀锌产出卷号 + "' ";
                    DataTable tb2 = pub.GetDataTable(pub.ConnectionString, sql);
                    if (tb2.Rows.Count > 0)
                    {
                        sql = " update Bus_ZincOutput set OutputEndStatus='被彩涂使用'   where OriginalVolumeNew ='" + 镀锌产出卷号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "更新镀锌卷的后续状态");
                        状态 = "被彩涂使用";
                    }
                }

                else   //入库
                {
                    sql = "select * from Bus_LablePrint where 生产批号 = '" + 镀锌产出卷号 + "' and 是否已打印 = '是'";
                    DataTable tb4 = pub.GetDataTable(pub.ConnectionString, sql);
                    if (tb4.Rows.Count > 0)
                    {
                        sql = " update Bus_PicklingOutput set OutputEndStatus='已入库'   where OriginalVolumeNew ='" + 镀锌产出卷号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "更新镀锌卷的后续状态");
                        状态 = "已入库";
                    }
                }

            }
            else
            {
                状态 = "产出卷被删了";
            }
            return 状态;
        }

        internal static Bus_ZincOriginal Get镀锌投入信息(string WorkShopCode, string 投入卷号,out string 用来保存的原卷号)
        {
            string sql;
            用来保存的原卷号 = "";
            string 查询投入卷号1 = "PHS" + 投入卷号.Replace("PHS", "");  //酸洗
            string 查询投入卷号2 = "PHY" + 投入卷号.Replace("PHY", "");  //轧硬
            sql = @"select guid, WorkShopGuid, WorkShopCode, OriginalVolume, OriginalVolumeNew, OriginalSize, OriginalWeight, 
                OriginalMaterial, OriginalMeter, OriginalAddress, PlanSize, CreateID, Creator, CreateDate, ModifyID, Modifier, 
                ModifyDate, IsClosed, ColseUserId, ColseUserName, CloseDate, Customer, ZincThick 
  FROM      Bus_ZincOriginal
                where WorkShopCode='" + pub.全局工厂编号 + "' and (OriginalVolumeNew='" + 查询投入卷号1 + "' or OriginalVolumeNew='" + 查询投入卷号2 + "')";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_ZincOriginal> bus_zincoriginals = pub.GetTableToList<Bus_ZincOriginal>(tb);
                用来保存的原卷号 = bus_zincoriginals[0].OriginalVolumeNew;
                return bus_zincoriginals[0];
            }
            else
            {
                用来保存的原卷号 = "";
                return null;
            }
        }

        internal static Bus_LvZincOriginal Get镀铝锌投入信息(string WorkShopCode, string 投入卷号, out string 用来保存的原卷号)
        {
            string sql;
            用来保存的原卷号 = "";
            string 查询投入卷号1 = "PHS" + 投入卷号.Replace("PHS", "");  //酸洗
            string 查询投入卷号2 = "PHY" + 投入卷号.Replace("PHY", "");  //轧硬
            sql = @"select guid, WorkShopGuid, WorkShopCode, OriginalVolume, OriginalVolumeNew, OriginalSize, OriginalWeight, 
                OriginalMaterial, OriginalMeter, OriginalAddress, PlanSize, CreateID, Creator, CreateDate, ModifyID, Modifier, 
                ModifyDate, IsClosed, ColseUserId, ColseUserName, CloseDate, Customer, ZincThick 
                FROM      Bus_LvZincOriginal
                where WorkShopCode='" + pub.全局工厂编号 + "' and (OriginalVolumeNew='" + 查询投入卷号1 + "' or OriginalVolumeNew='" + 查询投入卷号2 + "')";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_LvZincOriginal> bus_zincoriginals = pub.GetTableToList<Bus_LvZincOriginal>(tb);
                用来保存的原卷号 = bus_zincoriginals[0].OriginalVolumeNew;
                return bus_zincoriginals[0];
            }
            else
            {
                用来保存的原卷号 = "";
                return null;
            }
        }
        internal static Bus_ZincOutput Get镀锌产出卷信息(string 产出卷号)
        {
            string sql;
            sql = @"SELECT   OutputGuid, guid, VolumeCodeNew,Row, OutputVolumeNew, OutputSize, OutputThick, OutputWidth, OutputMaterial, OutputWeight, OutputMeter,
                OutputQualityGrade, OutputQualityInformation, OutputEndStatus, OutputNext, PrintTimes, DepartCode, DepartName, 
                WorkLineCode, WorkLineName, WorkTeamCode, WorkTeamName, DayShiftCode, DayShiftName, CreateID, Creator, 
                CreateDate, ModifyID, Modifier, ModifyDate
FROM      Bus_ZincOutput where OutputVolumeNew='" + 产出卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_ZincOutput> bus_zincoutputs = pub.GetTableToList<Bus_ZincOutput>(tb);
                return bus_zincoutputs[0];
            }
            else
            {
                return null;
            }
        }

        internal static string Get彩涂报工guid(string 投入卷号)
        {
            string sql;
            string 查询投入卷号 = "PHD" + 投入卷号.Replace("PHD", "");
            
            sql = "select guid from Bus_PaintOriginal where OriginalVolumeNew ='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                return tb.Rows[0]["guid"].ToString();
            }
            else
            {
                //产生一次
                string guid = Guid.NewGuid().ToString();

                sql = "insert into Bus_PaintOriginal( guid, WorkShopGuid, WorkShopCode, OriginalVolume, OriginalVolumeNew, OriginalSize,   ";
                sql += " OriginalMaterial, OriginalWeight,OriginalMeter,  PlanSize, OriginalAddress,  CreateID, Creator, CreateDate, IsClosed) ";
                sql += " select '" + guid + "',WorkShopGuid ,工厂编号,'',卷号,规格型号,材质,重量,米数,计划产出规格,产地,";
                sql += " '" + pub.sys_user.User_Id + "','" + pub.sys_user.UserTrueName + "',getdate(),'N' from View_已镀锌未彩涂 where 卷号='" + 查询投入卷号 + "'";
                if (pub.ExecuteSql(pub.ConnectionString, sql, "轧硬报工投入卷信息塞入Bus_HardOriginal") > 0)
                {
                    return guid;
                }
                else
                {
                    return "";
                }

            }
        }

        internal static bool Is彩涂报工原始卷被关闭(string 投入卷号)
        {
            string sql;
            string 查询投入卷号 = "PHD" + 投入卷号.Replace("PHD", "");
            sql = "select IsClosed from Bus_PaintOriginal where  OriginalVolumeNew='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                if (tb.Rows[0]["IsClosed"].ToString() == "Y")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        internal static List<Bus_PaintOutput> Get彩涂产出卷信息All(string 投入卷号)
        {
            string sql;
            string 查询投入卷号 = "PHD" + 投入卷号.Replace("PHD", "");
            sql = @"SELECT   OutputGuid, guid, VolumeCodeNew,Row, OutputVolumeNew, OutputSize, OutputThick, OutputWidth, OutputMaterial, OutputWeight, OutputMeter,
                OutputQualityGrade, OutputQualityInformation, OutputEndStatus, OutputNext, PrintTimes, DepartCode, DepartName, 
                WorkLineCode, WorkLineName, WorkTeamCode, WorkTeamName, DayShiftCode, DayShiftName, CreateID, Creator, 
                CreateDate, ModifyID, Modifier, ModifyDate
FROM      Bus_PaintOutput where   VolumeCodeNew='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_PaintOutput> bus_paintoutputs = pub.GetTableToList<Bus_PaintOutput>(tb);
                return bus_paintoutputs;
            }
            else
            {
                return null;
            }
        }

        internal static Bus_PaintOutput Get彩涂产出卷信息(string 产出卷号)
        {
            string sql;
            
            sql = @"SELECT   OutputGuid, guid, VolumeCodeNew,Row, OutputVolumeNew, OutputSize, OutputThick, OutputWidth, OutputMaterial, OutputWeight, OutputMeter,
                OutputQualityGrade, OutputQualityInformation, OutputEndStatus, OutputNext, PrintTimes, DepartCode, DepartName, 
                WorkLineCode, WorkLineName, WorkTeamCode, WorkTeamName, DayShiftCode, DayShiftName, CreateID, Creator, 
                CreateDate, ModifyID, Modifier, ModifyDate
FROM      Bus_PaintOutput where OutputVolumeNew='" + 产出卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_PaintOutput> bus_paintoutputs = pub.GetTableToList<Bus_PaintOutput>(tb);
                return bus_paintoutputs[0];
            }
            else
            {
                return null;
            }
        }

        internal static string Get彩涂产出卷的后续状态(string 彩涂产出卷号)
        {
            ///1,根据卷号找到去向
            string 状态 = "未使用";     //只看彩涂
            string sql = @"SELECT   OutputNext FROM      Bus_PaintOutput where OutputVolumeNew='" + 彩涂产出卷号 + "'  ";
            DataTable tb1 = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb1.Rows.Count > 0)
            {
                string 去向 = tb1.Rows[0]["OutputNext"].ToString();
                if (去向 == "下线入库")
                {
                    ///检查入库单

                    sql = "select * from Bus_ProductInStock where VolumeCodeNew ='" + 彩涂产出卷号 + "'";
                    DataTable tb4 = pub.GetDataTable(pub.ConnectionString, sql);
                    if (tb4.Rows.Count > 0)
                    {
                        sql = " update Bus_PaintOutput set OutputEndStatus='已入库'   where OriginalVolumeNew ='" + 彩涂产出卷号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "更新彩涂卷的后续状态");
                        状态 = "已入库";
                    }
                }
            }
            else
            {
                状态 = "产出卷被删了";
            }
            return 状态;
        }

        internal static Bus_PaintOriginal Get彩涂投入信息(string WorkShopCode, string 投入卷号,out  string 用来保存的原卷号)
        {
            string sql;
            string 查询投入卷号 = "PHD" + 投入卷号.Replace("PHD", "");
            sql = @"SELECT    guid, WorkShopGuid, WorkShopCode, OriginalVolume, OriginalVolumeNew, OriginalSize, OriginalWeight,OriginalMeter, 
                   OriginalMaterial, PlanSize, CreateID, Creator, CreateDate, ModifyID, Modifier, ModifyDate, IsClosed, ColseUserId, 
                   ColseUserName, CloseDate  FROM      [Bus_PaintOriginal] where WorkShopCode='" + WorkShopCode + "' and OriginalVolumeNew='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_PaintOriginal> bus_paintoriginals = pub.GetTableToList<Bus_PaintOriginal>(tb);
                用来保存的原卷号 = bus_paintoriginals[0].OriginalVolumeNew;
                return bus_paintoriginals[0];
            }
            else
            {
                用来保存的原卷号 = "";
                return null;
            }
        }

        internal static Bus_CoverFireOriginal Get罩退投入信息(string WorkShopCode, string 投入卷号,out string 用来保存的原卷号 )
        {
            string sql;
            sql = @"SELECT    guid, WorkShopGuid, WorkShopCode, OriginalVolume, OriginalVolumeNew, OriginalSize, OriginalWeight, 
                OriginalMaterial, OriginalAddress, OriginalMeter, PlanSize, CreateID, Creator, CreateDate, ModifyID, Modifier, 
                ModifyDate, IsClosed, ColseUserId, ColseUserName, CloseDate, Customer
  FROM      [Bus_CoverFireOriginal] where WorkShopCode='" + WorkShopCode + "' and OriginalVolumeNew='" + 投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_CoverFireOriginal> bus_coverfireoriginals = pub.GetTableToList<Bus_CoverFireOriginal>(tb);
                用来保存的原卷号 = bus_coverfireoriginals[0].OriginalVolumeNew;
                return bus_coverfireoriginals[0];
            }
            else
            {
                用来保存的原卷号 = "";
                return null;
            }
        }

        internal static string Get罩退报工guid(string 投入卷号)
        {
            string sql;
            string 查询投入卷号 = "PHY" + 投入卷号.Replace("PHY", "");
            sql = "select guid from Bus_PaintOriginal where OriginalVolumeNew ='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                return tb.Rows[0]["guid"].ToString();
            }
            else
            {
                //产生一次
                string guid = Guid.NewGuid().ToString();

                sql = "insert into Bus_CoverFireOriginal( guid, WorkShopGuid, WorkShopCode, OriginalVolume, OriginalVolumeNew, OriginalSize,   ";
                sql += " OriginalMaterial, OriginalWeight,OriginalMeter,    CreateID, Creator, CreateDate, IsClosed) ";
                sql += " select '" + guid + "',WorkShopGuid ,工厂编号,'',卷号,酸洗产出规格,材质,重量,米数,";
                sql += " '" + pub.sys_user.User_Id + "','" + pub.sys_user.UserTrueName + "',getdate(),'N' from View_已轧硬未罩退 where 卷号='" + 查询投入卷号 + "'";
                if (pub.ExecuteSql(pub.ConnectionString, sql, "罩退报工投入卷信息塞入Bus_HardOriginal") > 0)
                {
                    return guid;
                }
                else
                {
                    return "";
                }

            }
        }

        internal static bool Is罩退报工原始卷被关闭(string 投入卷号)
        {
            string sql;
            string 查询投入卷号 = "PHY" + 投入卷号.Replace("PHY", "");
            sql = "select IsClosed from Bus_CoverFireOriginal where  OriginalVolumeNew='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                if (tb.Rows[0]["IsClosed"].ToString() == "Y")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        internal static List<Bus_CoverFireOutput> Get罩退产出卷信息All(string 投入卷号)
        {
            string sql;
            sql = @"SELECT   OutputGuid, guid, VolumeCodeNew,Row, OutputVolumeNew, OutputSize, OutputThick, OutputWidth, OutputMaterial, OutputWeight, OutputMeter,
                OutputQualityGrade, OutputQualityInformation, OutputEndStatus, OutputNext, PrintTimes, DepartCode, DepartName, 
                WorkLineCode, WorkLineName, WorkTeamCode, WorkTeamName, DayShiftCode, DayShiftName, CreateID, Creator, 
                CreateDate, ModifyID, Modifier, ModifyDate
FROM      Bus_CoverFireOutput where VolumeCodeNew='" + 投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_CoverFireOutput> bus_coverfireoutputs = pub.GetTableToList<Bus_CoverFireOutput>(tb);
                return bus_coverfireoutputs;
            }
            else
            {
                return null;
            }
        }

        internal static string Get罩退产出卷的后续状态(string 罩退产出卷号)
        {
            ///1,根据卷号找到去向
            string 状态 = "未使用";     //只看彩涂
            string sql = @"SELECT     OutputNext  FROM Bus_CoverFireOutput  where OutputVolumeNew='" + 罩退产出卷号 + "'  ";
            DataTable tb1 = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb1.Rows.Count > 0)
            {
                string 去向 = tb1.Rows[0]["OutputNext"].ToString();
                if (去向 == "下线入库")
                {
                    ///检查入库单

                    sql = "select * from Bus_ProductInStock where VolumeCodeNew ='" + 罩退产出卷号 + "'";
                    DataTable tb4 = pub.GetDataTable(pub.ConnectionString, sql);
                    if (tb4.Rows.Count > 0)
                    {
                        sql = " update Bus_CoverFireOutput set OutputEndStatus='已入库'   where OutputVolumeNew ='" + 罩退产出卷号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "更新罩退卷的后续状态");
                        状态 = "已入库";
                    }
                }
            }
            else
            {
                状态 = "产出卷被删了";
            }
            return 状态;
        }

        internal static Bus_CoverFireOutput Get罩退产出卷信息(string 产出卷号)
        {
            string sql;
            sql = @"SELECT   OutputGuid, guid, VolumeCodeNew,Row, OutputVolumeNew, OutputSize, OutputThick, OutputWidth, OutputMaterial, OutputWeight, OutputMeter,
                OutputQualityGrade, OutputQualityInformation, OutputEndStatus, OutputNext, PrintTimes, DepartCode, DepartName, 
                WorkLineCode, WorkLineName, WorkTeamCode, WorkTeamName, DayShiftCode, DayShiftName, CreateID, Creator, 
                CreateDate, ModifyID, Modifier, ModifyDate
FROM      Bus_CoverFireOutput where OutputVolumeNew='" + 产出卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_CoverFireOutput> bus_coverfireoutputs = pub.GetTableToList<Bus_CoverFireOutput>(tb);
                return bus_coverfireoutputs[0];
            }
            else
            {
                return null;
            }
        }

        internal static string Get退火报工guid(string 投入卷号)
        {
            string sql;
            string 查询投入卷号 = "PHY" + 投入卷号.Replace("PHY", "");
            sql = "select guid from Bus_FireOriginal where OriginalVolumeNew ='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                return tb.Rows[0]["guid"].ToString();
            }
            else
            {
                //产生一次
                string guid = Guid.NewGuid().ToString();

                sql = "insert into Bus_FireOriginal( guid, WorkShopGuid, WorkShopCode, OriginalVolume, OriginalVolumeNew, OriginalSize,   ";
                sql += " OriginalMaterial, OriginalWeight,OriginalMeter,  PlanSize, OriginalAddress,  CreateID, Creator, CreateDate, IsClosed) ";
                sql += " select '" + guid + "',WorkShopGuid ,工厂编号,'',卷号,规格型号,材质,重量,米数,计划产出规格,产地,";
                sql += " '" + pub.sys_user.User_Id + "','" + pub.sys_user.UserTrueName + "',getdate(),'N' from View_已轧硬未退火 where 卷号='" + 查询投入卷号 + "'";
                if (pub.ExecuteSql(pub.ConnectionString, sql, "退火报工投入卷信息塞入Bus_FireOriginal") > 0)
                {
                    return guid;
                }
                else
                {
                    return "";
                }

            }
        }

        internal static bool Is退火报工原始卷被关闭(string 投入卷号)
        {
            string sql;
            string 查询投入卷号 = "PHY" + 投入卷号.Replace("PHY", "");
            sql = "select IsClosed from Bus_FireOriginal where  OriginalVolumeNew='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                if (tb.Rows[0]["IsClosed"].ToString() == "Y")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        internal static string Get硅钢报工guid(string 投入卷号)
        {
            string sql;
            string 查询投入卷号 = "PHY" + 投入卷号.Replace("PHY", "");
            sql = "select guid from Bus_SiOriginal where OriginalVolumeNew ='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                return tb.Rows[0]["guid"].ToString();
            }
            else
            {
                //产生一次
                string guid = Guid.NewGuid().ToString();

                sql = "insert into Bus_SiOriginal( guid, WorkShopGuid, WorkShopCode, OriginalVolume, OriginalVolumeNew, OriginalSize,   ";
                sql += " OriginalMaterial, OriginalWeight,OriginalMeter,  PlanSize, OriginalAddress,  CreateID, Creator, CreateDate, IsClosed) ";
                sql += " select '" + guid + "',WorkShopGuid ,工厂编号,'',卷号,规格型号,材质,重量,米数,计划产出规格,产地,";
                sql += " '" + pub.sys_user.User_Id + "','" + pub.sys_user.UserTrueName + "',getdate(),'N' from View_已轧硬未硅钢 where 卷号='" + 查询投入卷号 + "'";
                if (pub.ExecuteSql(pub.ConnectionString, sql, "硅钢报工投入卷信息塞入Bus_SiOriginal") > 0)
                {
                    return guid;
                }
                else
                {
                    return "";
                }

            }
        }

        internal static bool Is硅钢报工原始卷被关闭(string 投入卷号)
        {
            string sql;
            string 查询投入卷号 = "PHY" + 投入卷号.Replace("PHY", "");
            sql = "select IsClosed from Bus_SiOriginal where  OriginalVolumeNew='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                if (tb.Rows[0]["IsClosed"].ToString() == "Y")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        internal static List<Bus_SiOutput> Get硅钢产出卷信息All(string 投入卷号)
        {
            string sql;
            string 查询投入卷号 = "PHY" + 投入卷号.Replace("PHY", "");
            sql = @"SELECT   OutputGuid, guid, VolumeCodeNew,Row, OutputVolumeNew, OutputSize, OutputThick, OutputWidth, OutputMaterial, OutputWeight, OutputMeter,
                OutputQualityGrade, OutputQualityInformation, OutputEndStatus, OutputNext, PrintTimes, DepartCode, DepartName, 
                WorkLineCode, WorkLineName, WorkTeamCode, WorkTeamName, DayShiftCode, DayShiftName, CreateID, Creator, 
                CreateDate, ModifyID, Modifier, ModifyDate
FROM      Bus_SiOutput where   VolumeCodeNew='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_SiOutput> bus_sioutputs = pub.GetTableToList<Bus_SiOutput>(tb);
                return bus_sioutputs;
            }
            else
            {
                return null;
            }
        }

        internal static Bus_SiOutput Get硅钢产出卷信息(string 产出卷号)
        {
            string sql;
            sql = @"SELECT   OutputGuid, guid, VolumeCodeNew,Row, OutputVolumeNew, OutputSize, OutputThick, OutputWidth, OutputMaterial, OutputWeight, OutputMeter,
                OutputQualityGrade, OutputQualityInformation, OutputEndStatus, OutputNext, PrintTimes, DepartCode, DepartName, 
                WorkLineCode, WorkLineName, WorkTeamCode, WorkTeamName, DayShiftCode, DayShiftName, CreateID, Creator, 
                CreateDate, ModifyID, Modifier, ModifyDate
FROM      Bus_SiOutput where OutputVolumeNew='" + 产出卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_SiOutput> bus_sioutputs = pub.GetTableToList<Bus_SiOutput>(tb);
                return bus_sioutputs[0];
            }
            else
            {
                return null;
            }
        }

        internal static string Get硅钢产出卷的后续状态(string 硅钢产出卷号)
        {
            ///1,根据卷号找到去向
            string 状态 = "未使用";     //只看彩涂
            string sql = @"SELECT   OutputNext FROM      Bus_SiOutput where OutputVolumeNew='" + 硅钢产出卷号 + "'  ";
            DataTable tb1 = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb1.Rows.Count > 0)
            {
                string 去向 = tb1.Rows[0]["OutputNext"].ToString();
                if (去向 == "下线入库")
                {
                    ///检查入库单

                    sql = "select * from Bus_ProductInStock where VolumeCodeNew ='" + 硅钢产出卷号 + "'";
                    DataTable tb4 = pub.GetDataTable(pub.ConnectionString, sql);
                    if (tb4.Rows.Count > 0)
                    {
                        sql = " update Bus_PaintOutput set OutputEndStatus='已入库'   where OutputVolumeNew ='" + 硅钢产出卷号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "更新硅钢卷的后续状态");
                        状态 = "已入库";
                    }
                }
            }
            else
            {
                状态 = "产出卷被删了";
            }
            return 状态;
        }

        internal static Bus_SiOriginal Get硅钢投入信息(string WorkShopCode, string 投入卷号)
        {
            string sql;
            string 查询投入卷号 = "PHY" + 投入卷号.Replace("PHY", "");
            sql = @"SELECT    guid, WorkShopGuid, WorkShopCode, OriginalVolume, OriginalVolumeNew, OriginalSize, OriginalWeight,OriginalMeter, 
                   OriginalMaterial, PlanSize, CreateID, Creator, CreateDate, ModifyID, Modifier, ModifyDate, IsClosed, ColseUserId, 
                   ColseUserName, CloseDate  FROM      [Bus_SiOriginal] where WorkShopCode='" + WorkShopCode + "' and OriginalVolumeNew='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_SiOriginal> bus_sioriginals = pub.GetTableToList<Bus_SiOriginal>(tb);
                return bus_sioriginals[0];
            }
            else
            {

                return null;
            }
        }

        internal static List<Bus_FireOutput> Get退火产出卷信息All(string 投入卷号)
        {
            string sql;
            string 查询投入卷号 = "PHY" + 投入卷号.Replace("PHY", "");
            sql = @"SELECT   OutputGuid, guid, VolumeCodeNew,Row, OutputVolumeNew, OutputSize, OutputThick, OutputWidth, OutputMaterial, OutputWeight, OutputMeter,
                OutputQualityGrade, OutputQualityInformation, OutputEndStatus, OutputNext, PrintTimes, DepartCode, DepartName, 
                WorkLineCode, WorkLineName, WorkTeamCode, WorkTeamName, DayShiftCode, DayShiftName, CreateID, Creator, 
                CreateDate, ModifyID, Modifier, ModifyDate
FROM      Bus_FireOutput where   VolumeCodeNew='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_FireOutput> bus_fireoutputs = pub.GetTableToList<Bus_FireOutput>(tb);
                return bus_fireoutputs;
            }
            else
            {
                return null;
            }
        }

        internal static Bus_FireOutput Get退火产出卷信息(string 产出卷号)
        {
            string sql;
            sql = @"SELECT   OutputGuid, guid, VolumeCodeNew,Row, OutputVolumeNew, OutputSize, OutputThick, OutputWidth, OutputMaterial, OutputWeight, OutputMeter,
                OutputQualityGrade, OutputQualityInformation, OutputEndStatus, OutputNext, PrintTimes, DepartCode, DepartName, 
                WorkLineCode, WorkLineName, WorkTeamCode, WorkTeamName, DayShiftCode, DayShiftName, CreateID, Creator, 
                CreateDate, ModifyID, Modifier, ModifyDate
FROM      Bus_FireOutput where OutputVolumeNew='" + 产出卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_FireOutput> bus_fireoutputs = pub.GetTableToList<Bus_FireOutput>(tb);
                return bus_fireoutputs[0];
            }
            else
            {
                return null;
            }
        }

        internal static string Get退火产出卷的后续状态(string 退火产出卷号)
        {
            ///1,根据卷号找到去向
            string 状态 = "未使用";     //只看彩涂
            string sql = @"SELECT   OutputNext FROM      Bus_FireOutput where OutputVolumeNew='" + 退火产出卷号 + "'  ";
            DataTable tb1 = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb1.Rows.Count > 0)
            {
                string 去向 = tb1.Rows[0]["OutputNext"].ToString();
                if (去向 == "下线入库")
                {
                    ///检查入库单

                    sql = "select * from Bus_ProductInStock where VolumeCodeNew ='" + 退火产出卷号 + "'";
                    DataTable tb4 = pub.GetDataTable(pub.ConnectionString, sql);
                    if (tb4.Rows.Count > 0)
                    {
                        sql = " update Bus_PaintOutput set OutputEndStatus='已入库'   where OutputVolumeNew ='" + 退火产出卷号 + "'";
                        pub.ExecuteSql(pub.ConnectionString, sql, "更新退火卷的后续状态");
                        状态 = "已入库";
                    }
                }
            }
            else
            {
                状态 = "产出卷被删了";
            }
            return 状态;
        }

        internal static Bus_FireOriginal Get退火投入信息(string WorkShopCode, string 投入卷号)
        {
            string sql;
            string 查询投入卷号 = "PHY" + 投入卷号.Replace("PHY", "");
            sql = @"SELECT    guid, WorkShopGuid, WorkShopCode, OriginalVolume, OriginalVolumeNew, OriginalSize, OriginalWeight,OriginalMeter, 
                   OriginalMaterial, PlanSize, CreateID, Creator, CreateDate, ModifyID, Modifier, ModifyDate, IsClosed, ColseUserId, 
                   ColseUserName, CloseDate  FROM      [Bus_FireOriginal] where WorkShopCode='" + WorkShopCode + "' and OriginalVolumeNew='" + 查询投入卷号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_FireOriginal> bus_fireoriginals = pub.GetTableToList<Bus_FireOriginal>(tb);
                return bus_fireoriginals[0];
            }
            else
            {

                return null;
            }
        }

        public static void sendToNC产成品(string docCode)
        {
            string sql;
            sql = @"SELECT guid, StockInType, WorkShopCode, DocCode, DepartCode, SupplierCode, SupplierName, CreateID, Creator, 
                   CreateDate, ModifyID, Modifier, ModifyDate, ApproverID, Approver, ApproverDate, IsSendToNC, SendToNCDate
                   FROM      Bus_StockInV where docCode='" + docCode + "'";
            DataTable dtHeader = pub.GetDataTable(pub.ConnectionString, sql);

            if (dtHeader != null && dtHeader.Rows.Count > 0)
            {
                string sqlbody = @"SELECT [guid], [Bguid], [DocCode], [RowNumber], [WorkShopCode], [WarehouseCode], [StorageLocation], [T_CONTRACT_CODE],
                                [T_ORDER], [T_GOOD_UNIT], [T_GOOD_NUM], [T_GOOD_PRICE], [T_GOOD_MONEY], [VolumeCode], [VolumeCodeNew], [InventoryCode], 
                                [Size], [Thick], [Width], [Material], [Address], [Weight], [CID], [Virtual], [FaceStatus], [FaceDone], [NetWeight],
                                [Remark], [ProductDate],Grade,Meter,ZinCeng,PackageType,Customer,WorkLine,PingMing,Color
                                FROM      Bus_StockInVolume 
                                where 1=1 and DocCode='" + docCode + "' order by RowNumber  ";

                DataTable dtBody = pub.GetDataTable(pub.ConnectionString, sqlbody);
                if (dtBody != null && dtBody.Rows.Count > 0)
                {
                    NCModel.FinishedProductsInBillModel setInboundModel = new NCModel.FinishedProductsInBillModel();
                    //setInboundModel.corpName = "";
                    setInboundModel.region = "华东";
                    setInboundModel.ceateDate = DateTime.Parse(dtHeader.Rows[0]["CreateDate"].ToString()).ToString("yyyy-MM-dd");
                    //查询公司名称 公司编号
                    string sqlworkshop = @"SELECT  [WorkShopName]  FROM [Dic_WorkShop] where WorkShopCode = '" + dtHeader.Rows[0]["WorkShopCode"].ToString() + "'";
                    DataTable dtWorkShop = pub.GetDataTable(pub.ConnectionString, sqlworkshop);
                    if (dtWorkShop != null && dtWorkShop.Rows.Count > 0)
                    {
                        setInboundModel.corpName = dtWorkShop.Rows[0]["WorkShopName"].ToString();
                    }
                    else
                    {
                        MessageBox.Show("未能根据当前入库单公司编号查到对应的公司名称");
                        return;
                    }
                    //查仓库名称
                    string sqlwareName = "select WarehouseName from Dic_Warehouse where WarehouseCode = '"+ dtBody.Rows[0]["WarehouseCode"].ToString() + "'";
                    
                    DataTable dtWareName = pub.GetDataTable(pub.ConnectionString,sqlwareName);
                    if (dtWareName != null && dtWareName.Rows.Count > 0) {
                        setInboundModel.cWarehouseName = dtWareName.Rows[0]["WarehouseName"].ToString();
                    }
                    //setInboundModel.cWarehouseName = "涪镀锌一线成品库";
                     setInboundModel.cWhsmanagerCode = "";
                    setInboundModel.deptName = dtBody.Rows[0]["WorkLine"].ToString();
                    setInboundModel.cbizCode = "";
                    setInboundModel.remarks = "";

                    List<NCModel.Item> itemList = new List<NCModel.Item>();
                    for (int i = 0; i < dtBody.Rows.Count; i++)
                    {
                        NCModel.Item item = new NCModel.Item();
                        //明细ID
                        item.rowNo = dtBody.Rows[0]["Bguid"].ToString();
                        //存货编码
                        item.cinvbascode = dtBody.Rows[0]["InventoryCode"].ToString();
                        //批次号
                        item.vbatchcode = dtBody.Rows[0]["VolumeCodeNew"].ToString(); ;
                        //入库数量
                        decimal.TryParse(dtBody.Rows[0]["Weight"].ToString(), out decimal a);
                       decimal 重量 = Math.Round(a/1000, 4);
                        item.ninnum = 重量.ToString();
                        //入库日期
                        item.dbilldate = DateTime.Parse(dtBody.Rows[0]["ProductDate"].ToString()).ToString("yyyy-MM-dd");

                        //颜色 只有彩涂卷才有颜色
                        if (dtBody.Rows[0]["PingMing"]!= null && !string.IsNullOrEmpty(dtBody.Rows[0]["PingMing"].ToString()))
                        {
                            if (dtBody.Rows[0]["PingMing"].ToString().Contains("彩涂"))
                            {
                                item.vfree1 = dtBody.Rows[0]["Color"].ToString();
                            }
                            else
                            {
                                item.vfree1 = "";
                            }
                        }
                        
                        //长度
                        item.vfree2 = dtBody.Rows[0][ "Meter"].ToString();
                        //产地
                        if (string.IsNullOrEmpty(dtBody.Rows[0]["Address"]?.ToString()))
                        {
                            item.vfree3 = "万达";
                        }
                        else
                        {
                            item.vfree3 = dtBody.Rows[0]["Address"].ToString();
                        }

                        //表面状态  
                        item.vfree4 = "常规";
                        //表面厚度（锌层
                        item.vfree5 = dtBody.Rows[0]["ZinCeng"].ToString();
                        //等级 
                        item.vuserdef8 = dtBody.Rows[0]["Grade"].ToString();
                        //包装
                        item.vuserdef10 = dtBody.Rows[0]["PackageType"].ToString();
                        //客户
                        item.pk_defdoc13 = dtBody.Rows[0]["Customer"].ToString();

                        item.nprice = "";
                        item.nmny = "";
                        item.pk_defdoc11 = "";
                        item.pk_defdoc12 = "";
                        item.vnotebody = "";
                        item.vuserdef9 = "";
                        DateTime.TryParse(dtBody.Rows[0]["ProductDate"].ToString(), out DateTime date);
                        item.scrq = date.ToString("yyyy-MM-dd");
                        itemList.Add(item);
                    }


                    setInboundModel.items = itemList;

                    string jsonStr = JsonConvert.SerializeObject(setInboundModel);


                    
                    ExternalSystemToNcItfPortTypeClient client = new ExternalSystemToNcItfPortTypeClient();
                    string responseStr = client.finishedProductsInBill(jsonStr);


                    NCModel.NCResponseModel nCResponse = JsonConvert.DeserializeObject<NCModel.NCResponseModel>(responseStr);
                    //调用成功，改写NC状态
                    if (nCResponse.state == 0)
                    {
                        string sqlUpdate = @"update Bus_StockInV set SendToNCReturnValue = '"+ nCResponse.result+ "',IsSendToNC = 'Y' ,ToNCJson = '"+ jsonStr + "', SendToNCDate = '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where docCode = '" + docCode + "'";
                        int r = pub.ExecuteSql(pub.ConnectionString, sqlUpdate, "原料卷入库发送到NC");
                        if (r < 1)
                        {
                            MessageBox.Show("更新是否成功发送到NC失败");
                        }
                    }
                    else
                    {
                        string sqlUpdate = @"update Bus_StockInV set SendToNCReturnValue = '" + nCResponse?.msg + "',IsSendToNC = 'N' ,ToNCJson = '" + jsonStr + "', SendToNCDate = '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where docCode = '" + docCode + "'";
                        int r = pub.ExecuteSql(pub.ConnectionString, sqlUpdate, "原料卷入库发送到NC");
                    }
                    MessageBox.Show("抛送NC结果："+nCResponse.msg);
                }
                else
                {
                    MessageBox.Show("没查到行信息");
                }
            }
        }
        internal static void ListWorkLineAll(string 工厂编号, UIComboBox uiComboBox产线)
        {
            string sql = @"SELECT   guid, WorkShopCode, DepartGuid, DepartCode, WorkType, WorkLineCode, WorkLineName, AuditDate, AuditStatus, ";
            sql += " AuditId, Auditor, Remark, CreateID, Creator, CreateDate, ModifyID, Modifier, ModifyDate, V1, V2 FROM      Dic_WorkLine where WorkShopCode='"+ 工厂编号 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                uiComboBox产线.DataSource = tb;
                uiComboBox产线.DisplayMember = "WorkLineName";
                uiComboBox产线.ValueMember = "WorkLineCode";
                uiComboBox产线.Refresh();


            }
            else
            {

                uiComboBox产线.DataSource = null;
                
                uiComboBox产线.Refresh();
            }
        }
        internal static void List品名(UIComboBox uiComboBox品名,string 品名 ,string 质量等级 )
        {
            string sql="";
            if (品名!="镀锌" && 品名 != "彩涂" && 品名 != "罩退" && 品名 != "镀铝锌")
            {
                sql = "select distinct INVSHORTNAME from Dic_Inventory where INVNAME like '%" + 品名 + "%' ";
                if ( 质量等级=="B")
                {
                    sql += " and INVSHORTNAME like '%B%' ";
                }
                else
                {
                    sql += " and INVSHORTNAME not like '%B%' ";
                }
               sql +=" order by INVSHORTNAME ";

            }
            else if (品名 == "彩涂")
            {
                sql = "select distinct INVSHORTNAME from Dic_Inventory where (INVNAME like '%彩涂%' or INVNAME like '%镀锌%') ";
                if (质量等级 == "B")
                {
                    sql += " and INVSHORTNAME like '%B%' ";
                }
                else
                {
                    sql += " and INVSHORTNAME not like '%B%' ";
                }
                sql += " order by INVSHORTNAME ";
            }
            else if (品名 == "镀锌" || 品名 == "镀铝锌")
            {
                sql = "select distinct INVSHORTNAME from Dic_Inventory where ( INVNAME like '%镀锌%' or INVNAME like '%镀铝锌%' ) ";

                if (质量等级 == "B")
                {
                    sql += " and INVSHORTNAME like '%B%' ";
                }
                else
                {
                    sql += " and INVSHORTNAME not like '%B%' ";
                }
                sql +=" order by INVSHORTNAME ";
            }
            else if (品名 == "罩退")
            {
                sql = "select distinct INVSHORTNAME from Dic_Inventory where ( INVNAME like '%冷轧%' ) ";

                if (质量等级 == "B")
                {
                    sql += " and INVSHORTNAME like '%B%' and INVSHORTNAME not like '%硅钢%' ";
                }
                else
                {
                    sql += " and INVSHORTNAME not like '%B%' and INVSHORTNAME not like '%硅钢%' ";
                }
                sql += " order by INVSHORTNAME ";
            }

            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                uiComboBox品名.DataSource = tb;
                uiComboBox品名.DisplayMember = "INVSHORTNAME";
                uiComboBox品名.ValueMember = "INVSHORTNAME";
                uiComboBox品名.Refresh();
            }
            else
            {
                uiComboBox品名.DataSource = null;

                uiComboBox品名.Refresh();

            }
        }
       /// <summary>
       /// 显示已有的质量信息
       /// </summary>
       /// <param name="工厂编号"></param>
       /// <param name="workType"></param>
       /// <param name="uiComboBox质量信息"></param>
        internal static void ListQualityInfo(string 工厂编号, string workType, UIComboBox uiComboBox质量信息)
        {

            string sql;
            sql = "SELECT   guid, 工厂编号, 加工类别, 质量信息, 操作时间 FROM Bus_QualityInfo ";
            sql +=" where 工厂编号='"+ 工厂编号 + "' and 加工类别='" + workType + "' order by 操作时间 desc ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                uiComboBox质量信息.DataSource = tb;
                uiComboBox质量信息.DisplayMember = "质量信息";
                uiComboBox质量信息.ValueMember = "质量信息";
                uiComboBox质量信息.Refresh();
            }
            else
            {
                uiComboBox质量信息.DataSource = null;
                uiComboBox质量信息.Refresh();
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inventoryName"></param>
        /// <param name="outputSize"></param>
        /// <param name="outputMaterial"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        internal static string GetInventoryCode(string invshortname, string Size, string Material)
        {
            string sql;
            sql = "SELECT   guid, INVCODE, INVNAME, INVSHORTNAME, INVSPEC, INVTYPE, INVCLASSCODE, INVCLASSNAME, CreateID, Creator, ";
            sql += " CreateDate, ModifyID, Modifier, ModifyDate FROM      Dic_Inventory where INVSHORTNAME='" + invshortname + "' ";
            sql += " and INVSPEC='"+ Size + "' and INVTYPE='"+ Material + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb != null && tb.Rows.Count >0)
            {
                return tb.Rows[0]["INVCODE"].ToString();
            }
            else
            {
                return "";
            }
        }
         /// <summary>
         ///  根据工厂编号和加工类型得到钢号
         /// </summary>
         /// <param name="WorkType"></param>
         /// <param name="uiComboBox材质"></param>
        internal static void ListMaterial(string 工厂编号, string 加工类别, UIComboBox uiComboBox材质)
        {
            string sql;
            if (加工类别!="镀锌")
            {
                sql = "  select distinct ProductMaterial  from Dic_WorkTypeMaterial where workshopcode='" + 工厂编号 + "' and WorkType ='" + 加工类别 + "'";

            }
            else
            {
                sql = "  select distinct ProductMaterial  from Dic_WorkTypeMaterial where workshopcode='" + 工厂编号 + "' and  WorkType  in ('镀锌','彩基板') ";

            }
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                uiComboBox材质.DataSource = tb;
                uiComboBox材质.DisplayMember = "ProductMaterial";
                uiComboBox材质.ValueMember = "ProductMaterial";
                uiComboBox材质.Refresh();
            }
            else
            {
                uiComboBox材质.DataSource = null;
               
                uiComboBox材质.Refresh();
            }
        }
         /// <summary>
         /// 
         /// </summary>
         /// <param name="工厂编号1"></param>
         /// <param name="formWorkType"></param>
         /// <param name="outputQualityInformation"></param>
         /// <exception cref="NotImplementedException"></exception>
        internal static void UpdateQualityInformation(string 工厂编号, string 加工类别, string 质量信息)
        {
            string sql;
            sql = "SELECT   guid, 工厂编号, 加工类别, 质量信息, 操作时间 FROM Bus_QualityInfo ";
            sql += " where 工厂编号='" + 工厂编号 + "' and 加工类别='" + 加工类别 + "' and 质量信息='"+ 质量信息 + "' ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count == 0)
            {
                sql = "insert into Bus_QualityInfo(guid, 工厂编号, 加工类别, 质量信息, 操作时间)";
                sql += " values(newid(),'"+工厂编号+"','"+ 加工类别 + "','" + 质量信息 + "',getdate())";
                pub.ExecuteSql(pub.ConnectionString, sql,"更新质量信息");
            }
            
        }

        internal static void ListQualityStandard( string 加工类别, UIComboBox uiComboBox执行标准)
        {
            string sql;
            sql = "  select QualityStandard  from Dic_QualityStandard where   WorkTypeName ='" + 加工类别 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                uiComboBox执行标准.DataSource = tb;
                uiComboBox执行标准.DisplayMember = "QualityStandard";
                uiComboBox执行标准.ValueMember = "QualityStandard";
                uiComboBox执行标准.Refresh();
            }
            else
            {
                uiComboBox执行标准.DataSource = null;

                uiComboBox执行标准.Refresh();
            }
        }

        internal static void ListFaceDone(string 加工类别, UIComboBox uiComboBox表面处理)
        {
            string sql;

            if (加工类别!="镀锌")
            {
                sql = "  select distinct FaceDone  from Dic_FaceDone where   WorkType ='" + 加工类别 + "'";
            }

            else
            {
                sql = "  select distinct FaceDone  from Dic_FaceDone where   WorkType  in ('镀锌','彩基板') ";
            }
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                uiComboBox表面处理.DataSource = tb;
                uiComboBox表面处理.DisplayMember = "FaceDone";
                uiComboBox表面处理.ValueMember = "FaceDone";
                uiComboBox表面处理.Refresh();
            }
            else
            {
                uiComboBox表面处理.DataSource = null;

                uiComboBox表面处理.Refresh();
            }
        }

        internal static void UpdateColor(string colorName)
        {
            string sql;
            sql = "SELECT    ColorName FROM Dic_Color ";
            sql += " where ColorName='" + colorName + "'  ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count == 0)
            {
                sql = "insert into Dic_Color(guid, ColorName)";
                sql += " values(newid(),'" + colorName + "')";
                pub.ExecuteSql(pub.ConnectionString, sql, "更新颜色");
            }
        }

        internal static void ListColor(UIComboBox uiComboBox颜色)
        {
            string sql;
            sql = "SELECT   distinct ColorName FROM Dic_Color order by ColorName ";
           
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count >0)
            {
                uiComboBox颜色.DataSource = tb;
                uiComboBox颜色.DisplayMember = "ColorName";
                uiComboBox颜色.ValueMember = "ColorName";
                uiComboBox颜色.Refresh();
            }
        }

        internal static string Get员工所属班组(string userTrueName)
        {
            string sql;
            sql = "select 班组名称 from View_用户班组 where 用户名称 ='" + userTrueName + "'";
            DataTable tb= pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count >0)
            {
                return tb.Rows[0][0].ToString();
            }
            else
            {
                return "";
            }
            
        }
        /// <summary>
        /// 镀锌根据投入料的厚度，算出产出厚度
        /// </summary>
        /// <param name="厚度"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        internal static string Get镀锌厚度(decimal  厚度)
        {
            string sql;
            string 计算厚度;
            sql = "SELECT    计算厚度 FROM      Cal_Thick where 厚度下限<='"+ 厚度 + "' and 厚度上限>='"+ 厚度 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                计算厚度 = tb.Rows[0]["计算厚度"].ToString();
                return 计算厚度.ToString();
            }
            else
            {
                return "";
            }
           
        }

        internal static double Todouble(string s)
        {
            try
            {
                return double.Parse(s);
            }
            catch
            {
                return 0;
            }
        }

        internal static string Get卷计划产品规格(string 投入卷号)
        {
            //string 类型;
            //类型 = 投入卷号.Substring(0, 3);
            //if (类型=="PHS")
            //{
            //    string sql = "select ";

            //}
            //if (类型 == "PHY")
            //{

            //}
            return "";
        }
        /// <summary>
        ///  根据产线名称获得部门对象，产线部门同名了
        ///  
        /// </summary>
        /// <param name="selectedText"></param>
        /// <returns></returns>
        internal static Dic_Depart GetDepartByWorkLine(string 产线名称)
        {
            string sql;
            sql = @"SELECT   guid, WorkShopGuid, WorkShopCode, DepartCode, DepartName, ParentGuid, NcCode, AuditDate, AuditStatus, AuditId, ";
            sql += " Auditor, Remark, CreateID, Creator, CreateDate, ModifyID, Modifier, ModifyDate FROM      Dic_Depart where DepartName='" + 产线名称 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString,sql); 
            if (tb.Rows.Count >0)
            {
                List<Dic_Depart> departs = pub.GetTableToList<Dic_Depart>(tb);
                return departs[0];
            }
            else
            {
                return null;
            }
            
        }
       /// <summary>
       /// 根据产线名称获得产线对象
       /// </summary>
       /// <param name="产线名称"></param>
       /// <returns></returns>
        internal static Dic_WorkLine GetWorkLineByLineName(string 产线名称)
        {
            string sql;
            sql = @"SELECT   guid, WorkShopCode, DepartGuid, DepartCode, WorkType, WorkLineCode, WorkLineName, WareHouseName, 
                AuditDate, AuditStatus, AuditId, Auditor, Remark, CreateID, Creator, CreateDate, ModifyID, Modifier, ModifyDate, V1, 
                V2  FROM      Dic_WorkLine  where WorkLineName='" + 产线名称 + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Dic_WorkLine> worklines = pub.GetTableToList<Dic_WorkLine>(tb);
                return worklines[0];
            }
            else
            {
                return null;
            }
        }

        internal static string 根据产线获得仓库(string 产线名称)
        {
            string sql;
            string 产线仓库;
            sql = "SELECT    [WareHouseName] FROM      [Dic_WorkLine] where [WorkLineName]='" + 产线名称 + "' ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                产线仓库 = tb.Rows[0]["WareHouseName"].ToString();
                return 产线仓库.ToString();
            }
            else
            {
                return "";
            }
        }
        internal static string 根据产线获得仓库编号(string 产线名称)
        {
            string sql;
            string 产线仓库;
            sql = "SELECT    dic_warehouse.warehousecode FROM      [Dic_WorkLine] join dic_warehouse on dic_warehouse.WareHouseName=Dic_WorkLine.WareHouseName  where [WorkLineName]='" + 产线名称 + "' ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                产线仓库 = tb.Rows[0]["warehousecode"].ToString();
                return 产线仓库.ToString();
            }
            else
            {
                return "";
            }
        }

        internal static void ListWorkTeamAll(string 全局工厂编号, string 产线编号, UIComboBox uiComboBox班组)
        {
            string sql;
            sql = @"    SELECT   dbo.Dic_WorkLine.WorkShopCode, dbo.Dic_WorkTeam.WorkTeamCode, dbo.Dic_WorkTeam.WorkTeamName, 
                dbo.Dic_TeamLine.WorkLineCode
FROM      dbo.Dic_WorkLine INNER JOIN
                dbo.Dic_TeamLine ON dbo.Dic_WorkLine.WorkLineCode = dbo.Dic_TeamLine.WorkLineCode INNER JOIN
                dbo.Dic_WorkTeam ON dbo.Dic_TeamLine.WorkTeamGuid = dbo.Dic_WorkTeam.guid ";
            sql +=" where dbo.Dic_WorkLine.WorkShopCode='" + 全局工厂编号 + "' and  dbo.Dic_TeamLine.WorkLineCode='" + 产线编号 + "'";
            sql += " order by dbo.Dic_WorkTeam.WorkTeamCode ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                DataRow dr = tb.NewRow();
                dr["WorkTeamName"] = "全部";
                tb.Rows.InsertAt(dr,0);
                uiComboBox班组.DataSource = tb;
                uiComboBox班组.DisplayMember = "WorkTeamName";
                uiComboBox班组.ValueMember = "WorkTeamName";
                uiComboBox班组.Refresh();
            }
            else
            {
                uiComboBox班组.DataSource = null;
                uiComboBox班组.Refresh();
            }
        }
        /// <summary>
        /// 原料库的余额
        /// </summary>
        /// <param name="workShopCode"></param>
        /// <param name="volumeCodeNew"></param>
        /// <param name="WarehouseCode"></param>
        /// <returns></returns>
        internal static bool IsVolumeInStorage(string workShopCode, string volumeCodeNew, string WarehouseCode)
        {
            string sql;
            sql = "SELECT   WorkShopCode, WarehouseCode,  VolumeCode, VolumeCodeNew ";
            sql += " FROM      View_VolumeYLK余额 where workShopCode='" + workShopCode + "' and  WarehouseCode='" + WarehouseCode + "' and volumeCodeNew='" + volumeCodeNew + "'";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            return tb.Rows.Count > 0;
        }

        internal static void ListRankAll(string 全局工厂编号, UIComboBox uiComboBox查询等级)
        {
            string sql;
            sql = "SELECT   guid, WorkShopGuid, WorkShopCode, RankName, AuditDate, AuditStatus, AuditId, Auditor, Remark, CreateID, Creator, CreateDate, ModifyID, Modifier, ModifyDate FROM      Dic_Rank ";
            sql += " where WorkShopCode='" + 全局工厂编号 + "'    ";
            sql += "  order by RankName  ";

            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                DataRow dataRow = tb.NewRow();
                dataRow["RankName"] = "全部";
                tb.Rows.InsertAt(dataRow, 0);
                uiComboBox查询等级.DataSource = tb;
                uiComboBox查询等级.DisplayMember = "RankName";
                uiComboBox查询等级.ValueMember = "RankName";

                uiComboBox查询等级.Refresh();

            }
            else
            {

                uiComboBox查询等级.DataSource = null;
                uiComboBox查询等级.Refresh();
            }
        }
        /// <summary>
        /// 根据投入卷号返回镀锌计划
        /// </summary>
        /// <param name="投入卷号"></param>
        /// <returns></returns>
        internal static Bus_PlanZinc Get镀锌计划(string 投入卷号)
        {
            string sql;
            sql = @"SELECT   guid, WorkShopGuid, WorkShopCode, DepartGuid, DepartCode, WorkLineCode, WorkLineName, WorkDate, RowNumber, 
                OriginalSize, Address, VolumeCode, VolumeCodeNew, Weight, Meter, OutputSize, ProductSize, NextWorkType, Remark,
               Material, StorageLocation, MAC, CreateID, Creator, CreateDate, ApproverID, Approver, ApproverDate, IsSendToNC, 
                    SendToNCDate, Customer, ZincThick, SplitDesc  FROM      Bus_PlanZinc where VolumeCodeNew='" + 投入卷号 + "' ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
              if (tb.Rows.Count>0)
            {
                List<Bus_PlanZinc> bus_PlanZincs = pub.GetTableToList<Bus_PlanZinc>(tb);
                return bus_PlanZincs[0];

            }
              else
            {
                return null;
            }
        }

        internal static Bus_PlanLvZinc Get镀铝锌计划(string 投入卷号)
        {
            string sql;
            sql = @"SELECT   guid, WorkShopGuid, WorkShopCode, DepartGuid, DepartCode, WorkLineCode, WorkLineName, WorkDate, RowNumber, 
                OriginalSize, Address, VolumeCode, VolumeCodeNew, Weight, Meter, OutputSize, ProductSize, NextWorkType, Remark,
               Material, StorageLocation, MAC, CreateID, Creator, CreateDate, ApproverID, Approver, ApproverDate, IsSendToNC, 
                    SendToNCDate, Customer, ZincThick, SplitDesc  FROM      Bus_PlanLvZinc where VolumeCodeNew='" + 投入卷号 + "' ";
            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            if (tb.Rows.Count > 0)
            {
                List<Bus_PlanLvZinc> bus_PlanZincs = pub.GetTableToList<Bus_PlanLvZinc>(tb);
                return bus_PlanZincs[0];

            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="text1"></param>
        /// <param name="text2"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        internal static bool 符合理算厚度(decimal 成品厚度, decimal 理算厚度)
        {
            decimal 计算厚度 =pub.Todecimal( Get镀锌厚度(理算厚度));
            decimal 厚度 = pub.Todecimal(成品厚度);
                if (计算厚度== 厚度)
            {
                return true;    
            }
                else
            {
                return false;
            }

        }
        internal static bool 产出卷是否打印入库(string 生产批号)
        {
            string sqlLabelPrint = "select 生产批号 from Bus_LablePrint  where 生产批号 = '"
                                              + 生产批号 + "' and (是否已打印 = '是' or 是否抛送NC = 'Y')";
            DataTable dt = pub.GetDataTable(pub.ConnectionString, sqlLabelPrint);
            if (dt != null && dt.Rows.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

      private static  string OraconnectionString = ConfigurationManager.AppSettings["OraconnectionString"].ToString();

        public static DataTable OraQuery(string sql)
        {
            using (OracleConnection connection = new OracleConnection(OraconnectionString))
            {
                DataSet ds = new DataSet();
                try
                {
                    connection.Open();
                    OracleDataAdapter command = new OracleDataAdapter(sql, connection);
                    command.Fill(ds, "ds");
                    return ds.Tables[0];
                }
                catch (System.Data.OracleClient.OracleException ex)
                {

                }
                return new DataTable();

            }
        }

        public static int 下线入库(string 表名, string id,string 生产批号,string 来源种类,string 仓库,string 锌层,string 包装形式)
        {
            string sql = "";
            sql = "delete Bus_LablePrint where 生产批号='" + 生产批号 + "'";
            pub.ExecuteSql(pub.ConnectionString, sql, "小标签打印前清理");

            sql = "insert into Bus_LablePrint(guid, 来源种类,来源产线,工厂编号, 生产批号,  品名, 钢号, 条码, 长度, 规格, 等级, 表面状态, 表面处理, 净重, 备注, 生产日期,  操作ip, 操作人员, 操作时间 ,仓库,锌层,包装形式,班组,客户) ";

            sql += sql = "SELECT   NEWID(),'" + 来源种类 + "', WorkLineName 产线,'" + pub.全局工厂编号 + "',OutputVolumeNew 新卷号,InventoryName 品名,OutputMaterial 新材质, OutputVolumeNew 新卷号,OutputMeter 新米数,OutputSize 新规格"

                + ",OutputQualityGrade 质量等级,'', FaceDone 表面处理, OutputWeight 新重量,QualityStandard 执行标准,OutputDate 报工日期,'" + pub.getMac() + "','" + pub.sys_user.UserTrueName + "',getdate(),'" + 仓库 + "'"
                + ",'" + 锌层 + "','" + 包装形式 + "', WorkTeamName 班组,Customer 客户";
              
            sql += " FROM      "+ 表名 + " where OutputGuid = '" + id + "'";

           

            int r =  pub.ExecuteSql(pub.ConnectionString, sql, "小标签打印塞入");
            return r;
        }

        internal static DataTable 直接查询招采平台锌锭存货(string 存货名称, string 规格型号)
        {
            string sql;
            sql = @"select [T_GOOD_NAME]        ,[T_GOOD_CODE]            ,[T_GOOD_TYPE]        ,[T_GOOD_TYPE_CODE]            ,[T_GOOD_MODEL]
                ,[T_GOOD_UNIT] from [DASContract].[dbo].[VIEW_CIM] where T_GOOD_NAME='" + 存货名称 + "' and T_GOOD_MODEL='" + 规格型号 + "' and T_GOOD_TYPE = '锭类' and T_GOOD_STATUE = '启用'";
            DataTable tb = pub.GetDataTable(pub.purchaseConn, sql);
            return tb;
        }
    }
}
